import type { RpcCreateTxResult } from '../autogen/types/rpc/rpc-create-tx-result.cjs'; import type { Address } from '../types/primitives.cjs'; /** * 서버 측 prepare 결과 — 로컬 서명 단계의 입력이 된다. Locus 의 모든 * TX_CREATION RPC (예: locus_transferCoin) 가 이 값을 반환한다. */ export type PreparedTransaction = RpcCreateTxResult; /** * 두 번째 (submit) RPC 호출의 params[0] 에 병합되는 추가 필드들. * * 필드명은 RPC 스키마와 글자 그대로 (와이어에서 case-sensitive) 일치한다: * - `sign` 과 `signedHeight` 는 모든 TX_CREATION submit 에 존재. * - `keySign` 은 TX_OPEN_ACCOUNT 의 SignKeyBind 결과. * - `signByMasterKey` 는 TX_CHANGE_KEYPAIR 의 SignKeyBind 결과. * public key 필드 (mpk/pk/mpkey/masterPkey/newNormalPkey) 는 사용자가 * prepare 파라미터로 직접 넘기는 값이며 여기서 합성하지 않는다. */ export type TxSignAdditions = { sign: string; signedHeight: number; /** TX_OPEN_ACCOUNT: 초기 key-bind 메시지에 대한 master 서명. */ keySign?: string; /** TX_CHANGE_KEYPAIR: (newNpk, hash(currentNpk)) 에 대한 master 서명. */ signByMasterKey?: string; }; /** * 키 단위의 일반 signer. 구현체는 다음과 같다: * - localKeySource — secret key + public key 를 메모리에 보유. * - toKeySource — 호출자가 제공한 콜백 (keystore, 하드웨어 지갑, * 외부 지갑 앱 등). * 라이브러리는 secret key 를 직접 보관하지 않고, 콜백만 호출한다. */ export type KeySource = { /** 디버그/UI 라벨 — 'local' | 'keystore' | 'ledger' | 'trezor' | 'json-rpc' | 'custom' | string. */ type: string; /** * public key (normal 소스이면 npk, master 소스이면 mpk). Locus 의 PQ * 서명 알고리즘은 secret 으로부터 public 을 결정적으로 derive 할 수 * 없어, 호출자가 값을 주입해야 한다. */ getPublicKey: (args?: { signal?: AbortSignal; }) => Promise; /** 임의의 메시지에 서명한다 (보통 tx 해시). */ signMessage: (args: { message: string; signal?: AbortSignal; }) => Promise; /** * changeKey 흐름용 서명: master KeySource 가 새 normal public key 를 * 이전 키에 바인드한다. 이 함수는 master 소스만 제공할 것으로 기대하며, * 이를 필요로 하는 wallet action 을 signKeyBind 구현 없는 KeySource 로 * 호출하면 SignKeyBindUnsupportedError 가 발생한다. * * 최초 key bind (TX_OPEN_ACCOUNT) 의 경우 currentNpk 는 빈 문자열 — 노드는 * 이를 BlankShortDigest 로 해석한다. */ signKeyBind?: (args: { newNpk: string; currentNpk: string; signal?: AbortSignal; }) => Promise; }; /** * Locus account 모델: 두 개의 key source (master + normal). 라이브러리는 * TX 마다 어느 소스로 라우팅할지 accounts/signing/txKeyPolicy.mts 의 * TX 타입별 정책으로 결정한다. */ export type DualKeyAccount = { type: 'locus-dual-key'; address: Address; master: KeySource; normal: KeySource; /** * _prepareTransaction 이 첫 RPC 호출 전에 부르는 선택적 훅. * TX_OPEN_ACCOUNT / TX_CHANGE_KEYPAIR 의 경우 prepare RPC 단계에서도 * 노드가 master 가 증명한 key-bind 서명을 검증하므로 prepare 전에 * 미리 채워져 있어야 한다. 변환된 `params` 를 반환하면 dualKeyAccount * 가 `keySign` / `signByMasterKey` 를 자동으로 채우고, 나머지 RPC 는 * pass-through 로 둔다. */ prepareParams?: (args: { method: string; params: readonly unknown[]; signal?: AbortSignal; }) => Promise; /** _signLocusTransaction 이 호출한다. 사용자 코드가 직접 부르지 않는다. */ signTransaction: (args: { prepared: PreparedTransaction; signal?: AbortSignal; }) => Promise; /** TX 외 메시지 서명용 escape hatch (예: 인증 challenge). */ signMessage: (args: { message: string; role?: 'master' | 'normal'; signal?: AbortSignal; }) => Promise; }; /** 라이브러리의 표준 account 타입으로 re-export. */ export type LocusAccount = DualKeyAccount;