* Signs a payload using a derived key. * @param algorithm The algorithm to use (e.g., "ed25519", "secp256k1", "secp256k1_prehashed") * @param data The data to sign. If algorithm is "secp256k1_prehashed", this must be a 32-byte hash. * @returns A SignResponse containing the signature, signat
(algorithm: string, data: string | Buffer | Uint8Array)
| 355 | * @returns A SignResponse containing the signature, signature chain, and public key. |
| 356 | */ |
| 357 | async sign(algorithm: string, data: string | Buffer | Uint8Array): Promise<SignResponse> { |
| 358 | const hexData = to_hex(data); |
| 359 | if (algorithm === 'secp256k1_prehashed' && hexData.length !== 64) { |
| 360 | throw new Error(`Pre-hashed signing requires a 32-byte digest, but received ${hexData.length / 2} bytes`); |
| 361 | } |
| 362 | |
| 363 | const payload = JSON.stringify({ |
| 364 | algorithm: algorithm, |
| 365 | data: hexData |
| 366 | }); |
| 367 | |
| 368 | const result = await send_rpc_request<{ signature: string, signature_chain: string[], public_key: string }>(this.endpoint, '/Sign', payload); |
| 369 | |
| 370 | return Object.freeze({ |
| 371 | signature: new Uint8Array(Buffer.from(result.signature, 'hex')), |
| 372 | signature_chain: result.signature_chain.map(sig => new Uint8Array(Buffer.from(sig, 'hex'))), |
| 373 | public_key: new Uint8Array(Buffer.from(result.public_key, 'hex')), |
| 374 | __name__: 'SignResponse', |
| 375 | }); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Verifies a payload signature. |
no test coverage detected