signet.js 0.0.4 → 0.0.5-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/types/index.d.ts CHANGED
@@ -1,10 +1,13 @@
1
- import { NetworkId, Action, FinalExecutionOutcome } from '@near-wallet-selector/core';
2
1
  import BN from 'bn.js';
2
+ import { TransactionRequest, Address, SignableMessage, TypedDataDefinition, Hex, Hash, PublicClient, TransactionReceipt, WalletClient } from 'viem';
3
3
  import * as bitcoin from 'bitcoinjs-lib';
4
4
  import { EncodeObject } from '@cosmjs/proto-signing';
5
5
  import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
6
- import { TransactionRequest, Address, SignableMessage, TypedDataDefinition, Hex, PublicClient, WalletClient, TransactionReceipt, Hash } from 'viem';
7
6
  import { KeyPair } from '@near-js/crypto';
7
+ import { Action as Action$1 } from '@near-js/transactions';
8
+ import { TxExecutionStatus } from '@near-js/types';
9
+ import { NetworkId, Action, FinalExecutionOutcome } from '@near-wallet-selector/core';
10
+ import { KeyPair as KeyPair$1 } from 'near-api-js';
8
11
 
9
12
  interface SignArgs {
10
13
  /** The payload to sign as an array of 32 bytes */
@@ -15,7 +18,7 @@ interface SignArgs {
15
18
  key_version: number;
16
19
  }
17
20
  /**
18
- * Base contract interface required for compatibility with Chain instances like EVM and Bitcoin.
21
+ * Base contract interface required for compatibility with ChainAdapter instances like EVM and Bitcoin.
19
22
  *
20
23
  * See {@link EVM} and {@link Bitcoin} for example implementations.
21
24
  */
@@ -97,56 +100,171 @@ interface SigNetEvmMpcSignature {
97
100
  }
98
101
  type MPCSignature = NearNearMpcSignature | SigNetNearMpcSignature | SigNetEvmMpcSignature;
99
102
 
100
- interface BTCTransaction$1 {
101
- vout: Array<{
102
- scriptpubkey: string;
103
- value: number;
104
- }>;
103
+ declare const ENVS: {
104
+ readonly TESTNET_DEV: "TESTNET_DEV";
105
+ readonly TESTNET: "TESTNET";
106
+ readonly MAINNET: "MAINNET";
107
+ };
108
+ declare const CHAINS: {
109
+ readonly ETHEREUM: "ETHEREUM";
110
+ readonly NEAR: "NEAR";
111
+ };
112
+ /**
113
+ * Root public keys for the Sig Network Smart Contracts across different environments.
114
+ *
115
+ * These keys should never change.
116
+ */
117
+ declare const ROOT_PUBLIC_KEYS: Record<keyof typeof ENVS, NajPublicKey>;
118
+ /**
119
+ * Chain IDs used in the key derivation function (KDF) for deriving child public keys to
120
+ * distinguish between different chains.
121
+ *
122
+ * @see {@link deriveChildPublicKey} in cryptography.ts for usage details
123
+ */
124
+ declare const KDF_CHAIN_IDS: {
125
+ readonly ETHEREUM: "0x1";
126
+ readonly NEAR: "0x18d";
127
+ };
128
+ /**
129
+ * Contract addresses for different chains and environments.
130
+ *
131
+ * - Testnet Dev: Used for internal development, very unstable
132
+ * - Testnet: Used for external development, stable
133
+ * - Mainnet: Production contract address
134
+ *
135
+ * @see ChainSignatureContract documentation for implementation details
136
+ */
137
+ declare const CONTRACT_ADDRESSES: Record<keyof typeof CHAINS, Record<keyof typeof ENVS, string>>;
138
+
139
+ declare const constants_CHAINS: typeof CHAINS;
140
+ declare const constants_CONTRACT_ADDRESSES: typeof CONTRACT_ADDRESSES;
141
+ declare const constants_ENVS: typeof ENVS;
142
+ declare const constants_KDF_CHAIN_IDS: typeof KDF_CHAIN_IDS;
143
+ declare const constants_ROOT_PUBLIC_KEYS: typeof ROOT_PUBLIC_KEYS;
144
+ declare namespace constants {
145
+ export { constants_CHAINS as CHAINS, constants_CONTRACT_ADDRESSES as CONTRACT_ADDRESSES, constants_ENVS as ENVS, constants_KDF_CHAIN_IDS as KDF_CHAIN_IDS, constants_ROOT_PUBLIC_KEYS as ROOT_PUBLIC_KEYS };
105
146
  }
106
- interface BTCInput {
107
- txid: string;
108
- vout: number;
109
- value: number;
110
- scriptPubKey: Buffer;
147
+
148
+ declare const toRSV: (signature: MPCSignature) => RSVSignature;
149
+ /**
150
+ * Compresses an uncompressed public key to its compressed format following SEC1 standards.
151
+ * In SEC1, a compressed public key consists of a prefix (02 or 03) followed by the x-coordinate.
152
+ * The prefix indicates whether the y-coordinate is even (02) or odd (03).
153
+ *
154
+ * @param uncompressedPubKeySEC1 - The uncompressed public key in hex format, with or without '04' prefix
155
+ * @returns The compressed public key in hex format
156
+ * @throws Error if the uncompressed public key length is invalid
157
+ */
158
+ declare const compressPubKey: (uncompressedPubKeySEC1: UncompressedPubKeySEC1) => string;
159
+ /**
160
+ * Converts a NAJ public key to an uncompressed SEC1 public key.
161
+ *
162
+ * @param najPublicKey - The NAJ public key to convert (e.g. secp256k1:3Ww8iFjqTHufye5aRGUvrQqETegR4gVUcW8FX5xzscaN9ENhpkffojsxJwi6N1RbbHMTxYa9UyKeqK3fsMuwxjR5)
163
+ * @returns The uncompressed SEC1 public key (e.g. 04 || x || y)
164
+ */
165
+ declare const najToUncompressedPubKeySEC1: (najPublicKey: NajPublicKey) => UncompressedPubKeySEC1;
166
+ /**
167
+ * Derives a child public key from a parent public key using the sig.network v1.0.0 epsilon derivation scheme.
168
+ * The parent public keys are defined in @constants.ts
169
+ *
170
+ * @param najPublicKey - The parent public key in uncompressed SEC1 format (e.g. 04 || x || y)
171
+ * @param predecessorId - The predecessor ID is the address of the account calling the signer contract (e.g EOA or Contract Address)
172
+ * @param path - Optional derivation path suffix (defaults to empty string)
173
+ * @returns The derived child public key in uncompressed SEC1 format (04 || x || y)
174
+ */
175
+ declare function deriveChildPublicKey(rootUncompressedPubKeySEC1: UncompressedPubKeySEC1, predecessorId: string, path: string | undefined, chainId: string): UncompressedPubKeySEC1;
176
+
177
+ declare const cryptography_compressPubKey: typeof compressPubKey;
178
+ declare const cryptography_deriveChildPublicKey: typeof deriveChildPublicKey;
179
+ declare const cryptography_najToUncompressedPubKeySEC1: typeof najToUncompressedPubKeySEC1;
180
+ declare const cryptography_toRSV: typeof toRSV;
181
+ declare namespace cryptography {
182
+ export { cryptography_compressPubKey as compressPubKey, cryptography_deriveChildPublicKey as deriveChildPublicKey, cryptography_najToUncompressedPubKeySEC1 as najToUncompressedPubKeySEC1, cryptography_toRSV as toRSV };
111
183
  }
112
- type BTCOutput = {
113
- value: number;
114
- } | {
115
- address: string;
116
- value: number;
117
- } | {
118
- script: Buffer;
119
- value: number;
120
- };
121
- type BTCTransactionRequest = {
122
- publicKey: string;
123
- } & ({
124
- inputs: BTCInput[];
125
- outputs: BTCOutput[];
126
- from?: never;
127
- to?: never;
128
- value?: never;
129
- } | {
130
- inputs?: never;
131
- outputs?: never;
132
- from: string;
133
- to: string;
134
- value: string;
135
- });
136
- interface BTCUnsignedTransaction {
137
- psbt: bitcoin.Psbt;
138
- publicKey: string;
184
+
185
+ declare const index$7_cryptography: typeof cryptography;
186
+ declare namespace index$7 {
187
+ export { index$7_cryptography as cryptography };
139
188
  }
140
- type BTCNetworkIds = 'mainnet' | 'testnet' | 'regtest';
141
189
 
142
- type CosmosNetworkIds = string;
143
- type CosmosUnsignedTransaction = TxRaw;
144
- interface CosmosTransactionRequest {
145
- address: string;
146
- publicKey: string;
147
- messages: EncodeObject[];
148
- memo?: string;
149
- gas?: number;
190
+ declare abstract class ChainAdapter<TransactionRequest, UnsignedTransaction> {
191
+ /**
192
+ * Gets the native token balance and decimals for a given address
193
+ *
194
+ * @param address - The address to check
195
+ * @returns Promise resolving to an object containing:
196
+ * - balance: The balance as a bigint, in the chain's base units
197
+ * - decimals: The number of decimals used to format the balance
198
+ */
199
+ abstract getBalance(address: string): Promise<{
200
+ balance: bigint;
201
+ decimals: number;
202
+ }>;
203
+ /**
204
+ * Uses Sig Network Key Derivation Function to derive the address and public key. from a signer ID and string path.
205
+ *
206
+ * @param predecessor - The id/address of the account requesting signature
207
+ * @param path - The string path used to derive the key
208
+ * @returns Promise resolving to the derived address and public key
209
+ */
210
+ abstract deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
211
+ address: string;
212
+ publicKey: string;
213
+ }>;
214
+ /**
215
+ * Serializes an unsigned transaction to a string format.
216
+ * This is useful for storing or transmitting the transaction.
217
+ *
218
+ * @param transaction - The unsigned transaction to serialize
219
+ * @returns The serialized transaction string
220
+ */
221
+ abstract serializeTransaction(transaction: UnsignedTransaction): string;
222
+ /**
223
+ * Deserializes a transaction string back into an unsigned transaction object.
224
+ * This reverses the serialization done by serializeTransaction().
225
+ *
226
+ * @param serialized - The serialized transaction string
227
+ * @returns The deserialized unsigned transaction
228
+ */
229
+ abstract deserializeTransaction(serialized: string): UnsignedTransaction;
230
+ /**
231
+ * Prepares a transaction for Sig Network MPC signing by creating the necessary payloads.
232
+ * This method handles chain-specific transaction preparation including:
233
+ * - Fee calculation
234
+ * - Nonce/sequence management
235
+ * - UTXO selection (for UTXO-based chains)
236
+ * - Transaction encoding
237
+ *
238
+ * @param transactionRequest - The transaction request containing parameters like recipient, amount, etc.
239
+ * @returns Promise resolving to an object containing:
240
+ * - transaction: The unsigned transaction
241
+ * - hashesToSign: Array of payloads to be signed by MPC. The order of these payloads must match
242
+ * the order of signatures provided to finalizeTransactionSigning()
243
+ */
244
+ abstract prepareTransactionForSigning(transactionRequest: TransactionRequest): Promise<{
245
+ transaction: UnsignedTransaction;
246
+ hashesToSign: HashToSign[];
247
+ }>;
248
+ /**
249
+ * Adds Sig Network MPC-generated signatures to an unsigned transaction.
250
+ *
251
+ * @param params - Parameters for adding signatures
252
+ * @param params.transaction - The unsigned transaction to add signatures to
253
+ * @param params.rsvSignatures - Array of RSV signatures generated through MPC. Must be in the same order
254
+ * as the payloads returned by prepareTransactionForSigning()
255
+ * @returns The serialized signed transaction ready for broadcast
256
+ */
257
+ abstract finalizeTransactionSigning(params: {
258
+ transaction: UnsignedTransaction;
259
+ rsvSignatures: RSVSignature[];
260
+ }): string;
261
+ /**
262
+ * Broadcasts a signed transaction to the network.
263
+ *
264
+ * @param txSerialized - The serialized signed transaction
265
+ * @returns Promise resolving to the transaction hash/ID
266
+ */
267
+ abstract broadcastTx(txSerialized: string): Promise<string>;
150
268
  }
151
269
 
152
270
  type EVMUnsignedTransaction = TransactionRequest & {
@@ -190,77 +308,361 @@ interface UserOperationV6 {
190
308
  }
191
309
 
192
310
  /**
193
- Available ChainSignature contracts:
194
- - Mainnet: v1.signer
195
- - Testnet: v1.signer-prod.testnet
196
- - Development (unstable): v1.signer-dev.testnet
197
- */
198
- type ChainSignatureContractIds = string;
199
- type NearNetworkIds = 'mainnet' | 'testnet';
200
- interface ChainProvider {
201
- providerUrl: string;
202
- contract: ChainSignatureContractIds;
203
- }
204
- interface NearAuthentication {
205
- networkId: NearNetworkIds;
206
- accountId: string;
207
- }
208
- interface SuccessResponse {
209
- transactionHash: string;
210
- success: true;
211
- }
212
- interface FailureResponse {
213
- success: false;
214
- errorMessage: string;
215
- }
216
- type Response = SuccessResponse | FailureResponse;
217
- type EVMChainConfigWithProviders = ChainProvider;
218
- interface EVMRequest {
219
- transaction: EVMTransactionRequest;
220
- chainConfig: EVMChainConfigWithProviders;
221
- nearAuthentication: NearAuthentication;
222
- fastAuthRelayerUrl?: string;
223
- derivationPath: KeyDerivationPath;
224
- }
225
- type BTCChainConfigWithProviders = ChainProvider & {
226
- network: BTCNetworkIds;
227
- };
228
- interface BitcoinRequest {
229
- transaction: BTCTransactionRequest;
230
- chainConfig: BTCChainConfigWithProviders;
231
- nearAuthentication: NearAuthentication;
232
- fastAuthRelayerUrl?: string;
233
- derivationPath: KeyDerivationPath;
234
- }
235
- interface CosmosChainConfig {
236
- contract: ChainSignatureContractIds;
237
- chainId: CosmosNetworkIds;
238
- }
239
- interface CosmosRequest {
240
- chainConfig: CosmosChainConfig;
241
- transaction: CosmosTransactionRequest;
242
- nearAuthentication: NearAuthentication;
243
- derivationPath: KeyDerivationPath;
244
- fastAuthRelayerUrl?: string;
245
- }
246
-
247
- declare const mpcPayloadsToChainSigTransaction: ({ networkId, contractId, hashesToSign, path, }: {
248
- networkId: NetworkId;
249
- contractId: ChainSignatureContractIds;
250
- hashesToSign: HashToSign[];
251
- path: KeyDerivationPath;
252
- }) => Promise<{
253
- receiverId: string;
254
- actions: Action[];
255
- }>;
256
- declare const responseToMpcSignature: ({ response, }: {
257
- response: FinalExecutionOutcome;
258
- }) => RSVSignature | undefined;
311
+ * Implementation of the ChainAdapter interface for EVM-compatible networks.
312
+ * Handles interactions with Ethereum Virtual Machine based blockchains like Ethereum, BSC, Polygon, etc.
313
+ */
314
+ declare class EVM extends ChainAdapter<EVMTransactionRequest, EVMUnsignedTransaction> {
315
+ private readonly client;
316
+ private readonly contract;
317
+ /**
318
+ * Creates a new EVM chain instance
319
+ * @param params - Configuration parameters
320
+ * @param params.rpcUrl - URL of the EVM JSON-RPC provider (e.g., Infura endpoint)
321
+ * @param params.contract - Instance of the chain signature contract for MPC operations
322
+ */
323
+ constructor({ rpcUrl, contract, }: {
324
+ rpcUrl: string;
325
+ contract: BaseChainSignatureContract;
326
+ });
327
+ private attachGasAndNonce;
328
+ private transformRSVSignature;
329
+ private assembleSignature;
330
+ deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
331
+ address: string;
332
+ publicKey: string;
333
+ }>;
334
+ getBalance(address: string): Promise<{
335
+ balance: bigint;
336
+ decimals: number;
337
+ }>;
338
+ serializeTransaction(transaction: EVMUnsignedTransaction): `0x${string}`;
339
+ deserializeTransaction(serialized: `0x${string}`): EVMUnsignedTransaction;
340
+ prepareTransactionForSigning(transactionRequest: EVMTransactionRequest): Promise<{
341
+ transaction: EVMUnsignedTransaction;
342
+ hashesToSign: HashToSign[];
343
+ }>;
344
+ prepareMessageForSigning(message: EVMMessage): Promise<{
345
+ hashToSign: HashToSign;
346
+ }>;
347
+ prepareTypedDataForSigning(typedDataRequest: EVMTypedData): Promise<{
348
+ hashToSign: HashToSign;
349
+ }>;
350
+ /**
351
+ * This implementation is a common step for Biconomy and Alchemy.
352
+ * Key differences between implementations:
353
+ * - Signature format: Biconomy omits 0x00 prefix when concatenating, Alchemy includes it
354
+ * - Version support: Biconomy only supports v6, Alchemy supports both v6 and v7
355
+ * - Validation: Biconomy uses modules for signature validation, Alchemy uses built-in validation
356
+ */
357
+ prepareUserOpForSigning(userOp: UserOperationV7 | UserOperationV6, entryPointAddress?: Address, chainIdArgs?: number): Promise<{
358
+ userOp: UserOperationV7 | UserOperationV6;
359
+ hashToSign: HashToSign;
360
+ }>;
361
+ finalizeTransactionSigning({ transaction, rsvSignatures, }: {
362
+ transaction: EVMUnsignedTransaction;
363
+ rsvSignatures: RSVSignature[];
364
+ }): `0x02${string}`;
365
+ finalizeMessageSigning({ rsvSignature, }: {
366
+ rsvSignature: RSVSignature;
367
+ }): Hex;
368
+ finalizeTypedDataSigning({ rsvSignature, }: {
369
+ rsvSignature: RSVSignature;
370
+ }): Hex;
371
+ finalizeUserOpSigning({ userOp, rsvSignature, }: {
372
+ userOp: UserOperationV7 | UserOperationV6;
373
+ rsvSignature: RSVSignature;
374
+ }): UserOperationV7 | UserOperationV6;
375
+ broadcastTx(txSerialized: `0x${string}`): Promise<Hash>;
376
+ }
377
+
378
+ interface EVMFeeProperties {
379
+ gas: bigint;
380
+ maxFeePerGas: bigint;
381
+ maxPriorityFeePerGas: bigint;
382
+ }
383
+ declare function fetchEVMFeeProperties(client: PublicClient, transaction: TransactionRequest): Promise<EVMFeeProperties>;
384
+
385
+ type index$6_EVM = EVM;
386
+ declare const index$6_EVM: typeof EVM;
387
+ type index$6_EVMMessage = EVMMessage;
388
+ type index$6_EVMTransactionRequest = EVMTransactionRequest;
389
+ type index$6_EVMTypedData = EVMTypedData;
390
+ type index$6_EVMUnsignedTransaction = EVMUnsignedTransaction;
391
+ declare const index$6_fetchEVMFeeProperties: typeof fetchEVMFeeProperties;
392
+ declare namespace index$6 {
393
+ export { index$6_EVM as EVM, type index$6_EVMMessage as EVMMessage, type index$6_EVMTransactionRequest as EVMTransactionRequest, type index$6_EVMTypedData as EVMTypedData, type index$6_EVMUnsignedTransaction as EVMUnsignedTransaction, index$6_fetchEVMFeeProperties as fetchEVMFeeProperties };
394
+ }
395
+
396
+ interface BTCTransaction$1 {
397
+ vout: Array<{
398
+ scriptpubkey: string;
399
+ value: number;
400
+ }>;
401
+ }
402
+ interface BTCInput {
403
+ txid: string;
404
+ vout: number;
405
+ value: number;
406
+ scriptPubKey: Buffer;
407
+ }
408
+ type BTCOutput = {
409
+ value: number;
410
+ } | {
411
+ address: string;
412
+ value: number;
413
+ } | {
414
+ script: Buffer;
415
+ value: number;
416
+ };
417
+ type BTCTransactionRequest = {
418
+ publicKey: string;
419
+ } & ({
420
+ inputs: BTCInput[];
421
+ outputs: BTCOutput[];
422
+ from?: never;
423
+ to?: never;
424
+ value?: never;
425
+ } | {
426
+ inputs?: never;
427
+ outputs?: never;
428
+ from: string;
429
+ to: string;
430
+ value: string;
431
+ });
432
+ interface BTCUnsignedTransaction {
433
+ psbt: bitcoin.Psbt;
434
+ publicKey: string;
435
+ }
436
+ type BTCNetworkIds = 'mainnet' | 'testnet' | 'regtest';
437
+
438
+ declare abstract class BTCRpcAdapter {
439
+ abstract selectUTXOs(from: string, targets: BTCOutput[]): Promise<{
440
+ inputs: BTCInput[];
441
+ outputs: BTCOutput[];
442
+ }>;
443
+ abstract broadcastTransaction(transactionHex: string): Promise<string>;
444
+ abstract getBalance(address: string): Promise<number>;
445
+ abstract getTransaction(txid: string): Promise<BTCTransaction$1>;
446
+ }
447
+
448
+ declare class Mempool extends BTCRpcAdapter {
449
+ private readonly providerUrl;
450
+ constructor(providerUrl: string);
451
+ private fetchFeeRate;
452
+ private fetchUTXOs;
453
+ selectUTXOs(from: string, targets: BTCOutput[], confirmationTarget?: number): Promise<{
454
+ inputs: BTCInput[];
455
+ outputs: BTCOutput[];
456
+ }>;
457
+ broadcastTransaction(transactionHex: string): Promise<string>;
458
+ getBalance(address: string): Promise<number>;
459
+ getTransaction(txid: string): Promise<BTCTransaction$1>;
460
+ }
461
+
462
+ declare const BTCRpcAdapters: {
463
+ Mempool: typeof Mempool;
464
+ };
465
+
466
+ /**
467
+ * Implementation of the ChainAdapter interface for Bitcoin network.
468
+ * Handles interactions with both Bitcoin mainnet and testnet, supporting P2WPKH transactions.
469
+ */
470
+ declare class Bitcoin extends ChainAdapter<BTCTransactionRequest, BTCUnsignedTransaction> {
471
+ private static readonly SATOSHIS_PER_BTC;
472
+ private readonly network;
473
+ private readonly btcRpcAdapter;
474
+ private readonly contract;
475
+ /**
476
+ * Creates a new Bitcoin chain instance
477
+ * @param params - Configuration parameters
478
+ * @param params.network - Network identifier (mainnet/testnet)
479
+ * @param params.contract - Instance of the chain signature contract for MPC operations
480
+ * @param params.btcRpcAdapter - Bitcoin RPC adapter for network interactions
481
+ */
482
+ constructor({ network, contract, btcRpcAdapter, }: {
483
+ network: BTCNetworkIds;
484
+ contract: BaseChainSignatureContract;
485
+ btcRpcAdapter: BTCRpcAdapter;
486
+ });
487
+ /**
488
+ * Converts satoshis to BTC
489
+ * @param satoshis - Amount in satoshis
490
+ * @returns Amount in BTC
491
+ */
492
+ static toBTC(satoshis: number): number;
493
+ /**
494
+ * Converts BTC to satoshis
495
+ * @param btc - Amount in BTC
496
+ * @returns Amount in satoshis (rounded)
497
+ */
498
+ static toSatoshi(btc: number): number;
499
+ private fetchTransaction;
500
+ private static transformRSVSignature;
501
+ /**
502
+ * Creates a Partially Signed Bitcoin Transaction (PSBT)
503
+ * @param params - Parameters for creating the PSBT
504
+ * @param params.transactionRequest - Transaction request containing inputs and outputs
505
+ * @returns Created PSBT instance
506
+ */
507
+ createPSBT({ transactionRequest, }: {
508
+ transactionRequest: BTCTransactionRequest;
509
+ }): Promise<bitcoin.Psbt>;
510
+ getBalance(address: string): Promise<{
511
+ balance: bigint;
512
+ decimals: number;
513
+ }>;
514
+ deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
515
+ address: string;
516
+ publicKey: string;
517
+ }>;
518
+ serializeTransaction(transaction: BTCUnsignedTransaction): string;
519
+ deserializeTransaction(serialized: string): BTCUnsignedTransaction;
520
+ prepareTransactionForSigning(transactionRequest: BTCTransactionRequest): Promise<{
521
+ transaction: BTCUnsignedTransaction;
522
+ hashesToSign: HashToSign[];
523
+ }>;
524
+ finalizeTransactionSigning({ transaction: { psbt, publicKey }, rsvSignatures, }: {
525
+ transaction: BTCUnsignedTransaction;
526
+ rsvSignatures: RSVSignature[];
527
+ }): string;
528
+ broadcastTx(txSerialized: string): Promise<string>;
529
+ }
530
+
531
+ type index$5_BTCInput = BTCInput;
532
+ type index$5_BTCNetworkIds = BTCNetworkIds;
533
+ type index$5_BTCOutput = BTCOutput;
534
+ type index$5_BTCRpcAdapter = BTCRpcAdapter;
535
+ declare const index$5_BTCRpcAdapter: typeof BTCRpcAdapter;
536
+ declare const index$5_BTCRpcAdapters: typeof BTCRpcAdapters;
537
+ type index$5_BTCTransactionRequest = BTCTransactionRequest;
538
+ type index$5_BTCUnsignedTransaction = BTCUnsignedTransaction;
539
+ type index$5_Bitcoin = Bitcoin;
540
+ declare const index$5_Bitcoin: typeof Bitcoin;
541
+ declare namespace index$5 {
542
+ export { type index$5_BTCInput as BTCInput, type index$5_BTCNetworkIds as BTCNetworkIds, type index$5_BTCOutput as BTCOutput, index$5_BTCRpcAdapter as BTCRpcAdapter, index$5_BTCRpcAdapters as BTCRpcAdapters, type BTCTransaction$1 as BTCTransaction, type index$5_BTCTransactionRequest as BTCTransactionRequest, type index$5_BTCUnsignedTransaction as BTCUnsignedTransaction, index$5_Bitcoin as Bitcoin };
543
+ }
544
+
545
+ type CosmosNetworkIds = string;
546
+ type CosmosUnsignedTransaction = TxRaw;
547
+ interface CosmosTransactionRequest {
548
+ address: string;
549
+ publicKey: string;
550
+ messages: EncodeObject[];
551
+ memo?: string;
552
+ gas?: number;
553
+ }
554
+
555
+ /**
556
+ * Implementation of the ChainAdapter interface for Cosmos-based networks.
557
+ * Handles interactions with Cosmos SDK chains like Cosmos Hub, Osmosis, etc.
558
+ */
559
+ declare class Cosmos extends ChainAdapter<CosmosTransactionRequest, CosmosUnsignedTransaction> {
560
+ private readonly registry;
561
+ private readonly chainId;
562
+ private readonly contract;
563
+ private readonly endpoints?;
564
+ /**
565
+ * Creates a new Cosmos chain instance
566
+ * @param params - Configuration parameters
567
+ * @param params.chainId - Chain id for the Cosmos network
568
+ * @param params.contract - Instance of the chain signature contract for MPC operations
569
+ * @param params.endpoints - Optional RPC and REST endpoints
570
+ * @param params.endpoints.rpcUrl - Optional RPC endpoint URL
571
+ * @param params.endpoints.restUrl - Optional REST endpoint URL
572
+ */
573
+ constructor({ chainId, contract, endpoints, }: {
574
+ contract: BaseChainSignatureContract;
575
+ chainId: CosmosNetworkIds;
576
+ endpoints?: {
577
+ rpcUrl?: string;
578
+ restUrl?: string;
579
+ };
580
+ });
581
+ private transformRSVSignature;
582
+ private getChainInfo;
583
+ getBalance(address: string): Promise<{
584
+ balance: bigint;
585
+ decimals: number;
586
+ }>;
587
+ deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
588
+ address: string;
589
+ publicKey: string;
590
+ }>;
591
+ serializeTransaction(transaction: CosmosUnsignedTransaction): string;
592
+ deserializeTransaction(serialized: string): CosmosUnsignedTransaction;
593
+ prepareTransactionForSigning(transactionRequest: CosmosTransactionRequest): Promise<{
594
+ transaction: CosmosUnsignedTransaction;
595
+ hashesToSign: HashToSign[];
596
+ }>;
597
+ finalizeTransactionSigning({ transaction, rsvSignatures, }: {
598
+ transaction: CosmosUnsignedTransaction;
599
+ rsvSignatures: RSVSignature[];
600
+ }): string;
601
+ broadcastTx(txSerialized: string): Promise<string>;
602
+ }
603
+
604
+ type index$4_Cosmos = Cosmos;
605
+ declare const index$4_Cosmos: typeof Cosmos;
606
+ type index$4_CosmosNetworkIds = CosmosNetworkIds;
607
+ type index$4_CosmosTransactionRequest = CosmosTransactionRequest;
608
+ type index$4_CosmosUnsignedTransaction = CosmosUnsignedTransaction;
609
+ declare namespace index$4 {
610
+ export { index$4_Cosmos as Cosmos, type index$4_CosmosNetworkIds as CosmosNetworkIds, type index$4_CosmosTransactionRequest as CosmosTransactionRequest, type index$4_CosmosUnsignedTransaction as CosmosUnsignedTransaction };
611
+ }
259
612
 
260
- declare const transactionBuilder_mpcPayloadsToChainSigTransaction: typeof mpcPayloadsToChainSigTransaction;
261
- declare const transactionBuilder_responseToMpcSignature: typeof responseToMpcSignature;
262
- declare namespace transactionBuilder {
263
- export { transactionBuilder_mpcPayloadsToChainSigTransaction as mpcPayloadsToChainSigTransaction, transactionBuilder_responseToMpcSignature as responseToMpcSignature };
613
+ type index$3_ChainAdapter<TransactionRequest, UnsignedTransaction> = ChainAdapter<TransactionRequest, UnsignedTransaction>;
614
+ declare const index$3_ChainAdapter: typeof ChainAdapter;
615
+ declare namespace index$3 {
616
+ export { index$3_ChainAdapter as ChainAdapter, index$5 as btc, index$4 as cosmos, index$6 as evm };
617
+ }
618
+
619
+ type ChainSignatureContractIds = string;
620
+ type NearNetworkIds = 'mainnet' | 'testnet';
621
+ interface ChainProvider {
622
+ providerUrl: string;
623
+ contract: ChainSignatureContractIds;
624
+ }
625
+ interface NearAuthentication {
626
+ networkId: NearNetworkIds;
627
+ accountId: string;
628
+ }
629
+ interface SuccessResponse {
630
+ transactionHash: string;
631
+ success: true;
632
+ }
633
+ interface FailureResponse {
634
+ success: false;
635
+ errorMessage: string;
636
+ }
637
+ type Response = SuccessResponse | FailureResponse;
638
+ type EVMChainConfigWithProviders = ChainProvider;
639
+ interface EVMRequest {
640
+ transaction: EVMTransactionRequest;
641
+ chainConfig: EVMChainConfigWithProviders;
642
+ nearAuthentication: NearAuthentication;
643
+ fastAuthRelayerUrl?: string;
644
+ derivationPath: KeyDerivationPath;
645
+ }
646
+ type BTCChainConfigWithProviders = ChainProvider & {
647
+ network: BTCNetworkIds;
648
+ };
649
+ interface BitcoinRequest {
650
+ transaction: BTCTransactionRequest;
651
+ chainConfig: BTCChainConfigWithProviders;
652
+ nearAuthentication: NearAuthentication;
653
+ fastAuthRelayerUrl?: string;
654
+ derivationPath: KeyDerivationPath;
655
+ }
656
+ interface CosmosChainConfig {
657
+ contract: ChainSignatureContractIds;
658
+ chainId: CosmosNetworkIds;
659
+ }
660
+ interface CosmosRequest {
661
+ chainConfig: CosmosChainConfig;
662
+ transaction: CosmosTransactionRequest;
663
+ nearAuthentication: NearAuthentication;
664
+ derivationPath: KeyDerivationPath;
665
+ fastAuthRelayerUrl?: string;
264
666
  }
265
667
 
266
668
  declare const EVMTransaction: (req: EVMRequest, keyPair: KeyPair) => Promise<Response>;
@@ -274,9 +676,45 @@ declare namespace keypair {
274
676
  export { keypair_BTCTransaction as BTCTransaction, keypair_CosmosTransaction as CosmosTransaction, keypair_EVMTransaction as EVMTransaction };
275
677
  }
276
678
 
277
- declare const index$4_keypair: typeof keypair;
278
- declare namespace index$4 {
279
- export { index$4_keypair as keypair };
679
+ declare const signAndSend_keypair: typeof keypair;
680
+ declare namespace signAndSend {
681
+ export { signAndSend_keypair as keypair };
682
+ }
683
+
684
+ declare const mpcPayloadsToChainSigTransaction: ({ networkId, contractId, hashesToSign, path, }: {
685
+ networkId: NetworkId;
686
+ contractId: ChainSignatureContractIds;
687
+ hashesToSign: HashToSign[];
688
+ path: KeyDerivationPath;
689
+ }) => Promise<{
690
+ receiverId: string;
691
+ actions: Action[];
692
+ }>;
693
+ declare const responseToMpcSignature: ({ response, }: {
694
+ response: FinalExecutionOutcome;
695
+ }) => RSVSignature | undefined;
696
+ interface SendTransactionOptions {
697
+ until: TxExecutionStatus;
698
+ retryCount: number;
699
+ delay: number;
700
+ nodeUrl: string;
701
+ }
702
+ declare const sendTransactionUntil: ({ accountId, keypair, networkId, receiverId, actions, nonce, options, }: {
703
+ accountId: string;
704
+ keypair: KeyPair$1;
705
+ networkId: NetworkId;
706
+ receiverId: string;
707
+ actions: Action$1[];
708
+ nonce?: number;
709
+ options?: SendTransactionOptions;
710
+ }) => Promise<FinalExecutionOutcome>;
711
+
712
+ type transaction_SendTransactionOptions = SendTransactionOptions;
713
+ declare const transaction_mpcPayloadsToChainSigTransaction: typeof mpcPayloadsToChainSigTransaction;
714
+ declare const transaction_responseToMpcSignature: typeof responseToMpcSignature;
715
+ declare const transaction_sendTransactionUntil: typeof sendTransactionUntil;
716
+ declare namespace transaction {
717
+ export { type transaction_SendTransactionOptions as SendTransactionOptions, transaction_mpcPayloadsToChainSigTransaction as mpcPayloadsToChainSigTransaction, transaction_responseToMpcSignature as responseToMpcSignature, transaction_sendTransactionUntil as sendTransactionUntil };
280
718
  }
281
719
 
282
720
  interface ChainSignatureContractArgs {
@@ -284,6 +722,8 @@ interface ChainSignatureContractArgs {
284
722
  contractId: ChainSignatureContractIds;
285
723
  accountId?: string;
286
724
  keypair?: KeyPair;
725
+ rootPublicKey?: NajPublicKey;
726
+ sendTransactionOptions?: SendTransactionOptions;
287
727
  }
288
728
  /**
289
729
  * Implementation of the ChainSignatureContract for NEAR chains.
@@ -292,94 +732,47 @@ interface ChainSignatureContractArgs {
292
732
  * deployed on NEAR. It supports both view methods (which don't require authentication)
293
733
  * and change methods (which require a valid NEAR account and keypair).
294
734
  *
295
- * @extends AbstractChainSignatureContract
296
- */
297
- declare class ChainSignatureContract$1 extends ChainSignatureContract$2 {
298
- private readonly networkId;
299
- private readonly contractId;
300
- private readonly accountId;
301
- private readonly keypair;
302
- /**
303
- * Creates a new instance of the ChainSignatureContract for NEAR chains.
304
- *
305
- * @param args - Configuration options for the contract
306
- * @param args.networkId - The NEAR network ID (e.g. 'testnet', 'mainnet')
307
- * @param args.contractId - The contract ID of the deployed ChainSignatures contract
308
- * @param args.accountId - Optional NEAR account ID for signing transactions. Required for change methods.
309
- * @param args.keypair - Optional NEAR KeyPair for signing transactions. Required for change methods.
310
- */
311
- constructor({ networkId, contractId, accountId, keypair, }: ChainSignatureContractArgs);
312
- private getContract;
313
- getCurrentSignatureDeposit(): Promise<BN>;
314
- getDerivedPublicKey(args: {
315
- path: string;
316
- predecessor: string;
317
- }): Promise<UncompressedPubKeySEC1>;
318
- getPublicKey(): Promise<UncompressedPubKeySEC1>;
319
- sign(args: SignArgs): Promise<RSVSignature>;
320
- }
321
-
322
- declare const index$3_transactionBuilder: typeof transactionBuilder;
323
- declare namespace index$3 {
324
- export { ChainSignatureContract$1 as ChainSignatureContract, index$4 as signAndSend, index$3_transactionBuilder as transactionBuilder };
325
- }
326
-
327
- interface SignOptions {
328
- sign: {
329
- algo?: string;
330
- dest?: string;
331
- params?: string;
332
- };
333
- retry: {
334
- delay?: number;
335
- retryCount?: number;
336
- };
337
- }
338
- interface SignatureErrorData {
339
- requestId: string;
340
- responder: string;
341
- error: string;
342
- }
343
-
344
- /**
345
- * Implementation of the ChainSignatureContract for EVM chains.
346
- *
347
- * When signing data, the contract emits a SignatureRequested event with a requestId.
348
- * This requestId is used to track the signature request and retrieve the signature
349
- * once it's available. The sign method handles this process automatically by polling
350
- * for the signature using the requestId.
351
- */
352
- declare class ChainSignatureContract extends ChainSignatureContract$2 {
353
- private readonly publicClient;
354
- private readonly walletClient;
355
- private readonly contractAddress;
356
- private readonly rootPublicKey;
735
+ * @extends AbstractChainSignatureContract
736
+ */
737
+ declare class ChainSignatureContract$1 extends ChainSignatureContract$2 {
738
+ private readonly networkId;
739
+ private readonly contractId;
740
+ private readonly accountId;
741
+ private readonly keypair;
742
+ private readonly rootPublicKey?;
743
+ private readonly sendTransactionOptions?;
357
744
  /**
358
- * Creates a new instance of the ChainSignatureContract for EVM chains.
745
+ * Creates a new instance of the ChainSignatureContract for NEAR chains.
359
746
  *
360
747
  * @param args - Configuration options for the contract
361
- * @param args.publicClient - A Viem PublicClient instance for reading from the blockchain
362
- * @param args.walletClient - A Viem WalletClient instance for sending transactions
363
- * @param args.contractAddress - The address of the deployed ChainSignatures contract (e.g. `0x857ED3A242B59cC24144814a0DF41C397a3811E6`)
364
- * @param args.rootPublicKey - Optional root public key. If not provided, it will be derived from the contract address
748
+ * @param args.networkId - The NEAR network ID (e.g. 'testnet', 'mainnet')
749
+ * @param args.contractId - The contract ID of the deployed ChainSignatures contract
750
+ * @param args.accountId - Optional NEAR account ID for signing transactions. Required for change methods.
751
+ * @param args.keypair - Optional NEAR KeyPair for signing transactions. Required for change methods.
752
+ * @param args.rootPublicKey - Optional root public key for the contract. If not provided, it will be derived from the contract ID.
753
+ * @param args.sendTransactionOptions - Optional configuration for transaction sending behavior.
365
754
  */
366
- constructor(args: {
367
- publicClient: PublicClient;
368
- walletClient: WalletClient;
369
- contractAddress: Hex;
370
- rootPublicKey?: NajPublicKey;
371
- });
755
+ constructor({ networkId, contractId, accountId, keypair, rootPublicKey, sendTransactionOptions, }: ChainSignatureContractArgs);
756
+ private getContract;
372
757
  getCurrentSignatureDeposit(): Promise<BN>;
373
758
  getDerivedPublicKey(args: {
374
759
  path: string;
375
760
  predecessor: string;
376
761
  }): Promise<UncompressedPubKeySEC1>;
377
762
  getPublicKey(): Promise<UncompressedPubKeySEC1>;
378
- getLatestKeyVersion(): Promise<number>;
379
- sign(args: SignArgs, options?: SignOptions): Promise<RSVSignature>;
380
- private getRequestId;
381
- getErrorFromEvents(requestId: `0x${string}`, receipt: TransactionReceipt): Promise<SignatureErrorData | undefined>;
382
- getSignatureFromEvents(requestId: `0x${string}`, receipt: TransactionReceipt): Promise<RSVSignature | undefined>;
763
+ sign(args: SignArgs, options?: {
764
+ nonce?: number;
765
+ }): Promise<RSVSignature>;
766
+ private requireAccount;
767
+ }
768
+
769
+ declare const utils$1: {
770
+ transaction: typeof transaction;
771
+ signAndSend: typeof signAndSend;
772
+ };
773
+
774
+ declare namespace index$2 {
775
+ export { ChainSignatureContract$1 as ChainSignatureContract, utils$1 as utils };
383
776
  }
384
777
 
385
778
  declare const abi: ({
@@ -475,445 +868,181 @@ declare const abi: ({
475
868
  type: string;
476
869
  components?: undefined;
477
870
  })[];
478
- internalType: string;
479
- name: string;
480
- type: string;
481
- })[];
482
- internalType: string;
483
- name: string;
484
- type: string;
485
- }[];
486
- name: string;
487
- outputs: never[];
488
- stateMutability: string;
489
- type: string;
490
- anonymous?: undefined;
491
- })[];
492
-
493
- declare class ChainSignatureError extends Error {
494
- requestId: `0x${string}`;
495
- receipt: TransactionReceipt;
496
- constructor(message: string, requestId: `0x${string}`, receipt: TransactionReceipt);
497
- }
498
- declare class SignatureNotFoundError extends ChainSignatureError {
499
- constructor(requestId: `0x${string}`, receipt: TransactionReceipt);
500
- }
501
- declare class SignatureContractError extends ChainSignatureError {
502
- errorCode: string;
503
- constructor(errorCode: string, requestId: `0x${string}`, receipt: TransactionReceipt);
504
- }
505
- declare class SigningError extends ChainSignatureError {
506
- originalError?: Error;
507
- constructor(requestId: `0x${string}`, receipt: TransactionReceipt, originalError?: Error);
508
- }
509
-
510
- type errors_ChainSignatureError = ChainSignatureError;
511
- declare const errors_ChainSignatureError: typeof ChainSignatureError;
512
- type errors_SignatureContractError = SignatureContractError;
513
- declare const errors_SignatureContractError: typeof SignatureContractError;
514
- type errors_SignatureNotFoundError = SignatureNotFoundError;
515
- declare const errors_SignatureNotFoundError: typeof SignatureNotFoundError;
516
- type errors_SigningError = SigningError;
517
- declare const errors_SigningError: typeof SigningError;
518
- declare namespace errors {
519
- export { errors_ChainSignatureError as ChainSignatureError, errors_SignatureContractError as SignatureContractError, errors_SignatureNotFoundError as SignatureNotFoundError, errors_SigningError as SigningError };
520
- }
521
-
522
- type index$2_ChainSignatureContract = ChainSignatureContract;
523
- declare const index$2_ChainSignatureContract: typeof ChainSignatureContract;
524
- declare const index$2_abi: typeof abi;
525
- declare const index$2_errors: typeof errors;
526
- declare namespace index$2 {
527
- export { index$2_ChainSignatureContract as ChainSignatureContract, index$2_abi as abi, index$2_errors as errors };
528
- }
529
-
530
- declare namespace index$1 {
531
- export { index$2 as evm, index$3 as near };
532
- }
533
-
534
- declare const toRSV: (signature: MPCSignature) => RSVSignature;
535
- /**
536
- * Compresses an uncompressed public key to its compressed format following SEC1 standards.
537
- * In SEC1, a compressed public key consists of a prefix (02 or 03) followed by the x-coordinate.
538
- * The prefix indicates whether the y-coordinate is even (02) or odd (03).
539
- *
540
- * @param uncompressedPubKeySEC1 - The uncompressed public key in hex format, with or without '04' prefix
541
- * @returns The compressed public key in hex format
542
- * @throws Error if the uncompressed public key length is invalid
543
- */
544
- declare const compressPubKey: (uncompressedPubKeySEC1: UncompressedPubKeySEC1) => string;
545
- /**
546
- * Converts a NAJ public key to an uncompressed SEC1 public key.
547
- *
548
- * @param najPublicKey - The NAJ public key to convert (e.g. secp256k1:3Ww8iFjqTHufye5aRGUvrQqETegR4gVUcW8FX5xzscaN9ENhpkffojsxJwi6N1RbbHMTxYa9UyKeqK3fsMuwxjR5)
549
- * @returns The uncompressed SEC1 public key (e.g. 04 || x || y)
550
- */
551
- declare const najToUncompressedPubKeySEC1: (najPublicKey: NajPublicKey) => UncompressedPubKeySEC1;
552
- /**
553
- * Derives a child public key from a parent public key using the sig.network v1.0.0 epsilon derivation scheme.
554
- * The parent public keys are defined in @constants.ts
555
- *
556
- * @param najPublicKey - The parent public key in uncompressed SEC1 format (e.g. 04 || x || y)
557
- * @param predecessorId - The predecessor ID is the address of the account calling the signer contract (e.g EOA or Contract Address)
558
- * @param path - Optional derivation path suffix (defaults to empty string)
559
- * @returns The derived child public key in uncompressed SEC1 format (04 || x || y)
560
- */
561
- declare function deriveChildPublicKey(rootUncompressedPubKeySEC1: UncompressedPubKeySEC1, predecessorId: string, path: string | undefined, chainId: string): UncompressedPubKeySEC1;
562
-
563
- declare const cryptography_compressPubKey: typeof compressPubKey;
564
- declare const cryptography_deriveChildPublicKey: typeof deriveChildPublicKey;
565
- declare const cryptography_najToUncompressedPubKeySEC1: typeof najToUncompressedPubKeySEC1;
566
- declare const cryptography_toRSV: typeof toRSV;
567
- declare namespace cryptography {
568
- export { cryptography_compressPubKey as compressPubKey, cryptography_deriveChildPublicKey as deriveChildPublicKey, cryptography_najToUncompressedPubKeySEC1 as najToUncompressedPubKeySEC1, cryptography_toRSV as toRSV };
569
- }
570
-
571
- declare abstract class Chain<TransactionRequest, UnsignedTransaction> {
572
- /**
573
- * Gets the native token balance and decimals for a given address
574
- *
575
- * @param address - The address to check
576
- * @returns Promise resolving to an object containing:
577
- * - balance: The balance as a bigint, in the chain's base units
578
- * - decimals: The number of decimals used to format the balance
579
- */
580
- abstract getBalance(address: string): Promise<{
581
- balance: bigint;
582
- decimals: number;
583
- }>;
584
- /**
585
- * Uses Sig Network Key Derivation Function to derive the address and public key. from a signer ID and string path.
586
- *
587
- * @param predecessor - The id/address of the account requesting signature
588
- * @param path - The string path used to derive the key
589
- * @returns Promise resolving to the derived address and public key
590
- */
591
- abstract deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
592
- address: string;
593
- publicKey: string;
594
- }>;
595
- /**
596
- * Serializes an unsigned transaction to a string format.
597
- * This is useful for storing or transmitting the transaction.
598
- *
599
- * @param transaction - The unsigned transaction to serialize
600
- * @returns The serialized transaction string
601
- */
602
- abstract serializeTransaction(transaction: UnsignedTransaction): string;
603
- /**
604
- * Deserializes a transaction string back into an unsigned transaction object.
605
- * This reverses the serialization done by serializeTransaction().
606
- *
607
- * @param serialized - The serialized transaction string
608
- * @returns The deserialized unsigned transaction
609
- */
610
- abstract deserializeTransaction(serialized: string): UnsignedTransaction;
611
- /**
612
- * Prepares a transaction for Sig Network MPC signing by creating the necessary payloads.
613
- * This method handles chain-specific transaction preparation including:
614
- * - Fee calculation
615
- * - Nonce/sequence management
616
- * - UTXO selection (for UTXO-based chains)
617
- * - Transaction encoding
618
- *
619
- * @param transactionRequest - The transaction request containing parameters like recipient, amount, etc.
620
- * @returns Promise resolving to an object containing:
621
- * - transaction: The unsigned transaction
622
- * - hashesToSign: Array of payloads to be signed by MPC. The order of these payloads must match
623
- * the order of signatures provided to attachTransactionSignature()
624
- */
625
- abstract prepareTransactionForSigning(transactionRequest: TransactionRequest): Promise<{
626
- transaction: UnsignedTransaction;
627
- hashesToSign: HashToSign[];
628
- }>;
629
- /**
630
- * Adds Sig Network MPC-generated signatures to an unsigned transaction.
631
- *
632
- * @param params - Parameters for adding signatures
633
- * @param params.transaction - The unsigned transaction to add signatures to
634
- * @param params.rsvSignatures - Array of RSV signatures generated through MPC. Must be in the same order
635
- * as the payloads returned by prepareTransactionForSigning()
636
- * @returns The serialized signed transaction ready for broadcast
637
- */
638
- abstract attachTransactionSignature(params: {
639
- transaction: UnsignedTransaction;
640
- rsvSignatures: RSVSignature[];
641
- }): string;
642
- /**
643
- * Broadcasts a signed transaction to the network.
644
- *
645
- * @param txSerialized - The serialized signed transaction
646
- * @returns Promise resolving to the transaction hash/ID
647
- */
648
- abstract broadcastTx(txSerialized: string): Promise<string>;
649
- }
650
-
651
- /**
652
- * Implementation of the Chain interface for EVM-compatible networks.
653
- * Handles interactions with Ethereum Virtual Machine based blockchains like Ethereum, BSC, Polygon, etc.
654
- */
655
- declare class EVM extends Chain<EVMTransactionRequest, EVMUnsignedTransaction> {
656
- private readonly client;
657
- private readonly contract;
658
- /**
659
- * Creates a new EVM chain instance
660
- * @param params - Configuration parameters
661
- * @param params.rpcUrl - URL of the EVM JSON-RPC provider (e.g., Infura endpoint)
662
- * @param params.contract - Instance of the chain signature contract for MPC operations
663
- */
664
- constructor({ rpcUrl, contract, }: {
665
- rpcUrl: string;
666
- contract: BaseChainSignatureContract;
667
- });
668
- private attachGasAndNonce;
669
- private transformRSVSignature;
670
- private assembleSignature;
671
- deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
672
- address: string;
673
- publicKey: string;
674
- }>;
675
- getBalance(address: string): Promise<{
676
- balance: bigint;
677
- decimals: number;
678
- }>;
679
- serializeTransaction(transaction: EVMUnsignedTransaction): `0x${string}`;
680
- deserializeTransaction(serialized: `0x${string}`): EVMUnsignedTransaction;
681
- prepareTransactionForSigning(transactionRequest: EVMTransactionRequest): Promise<{
682
- transaction: EVMUnsignedTransaction;
683
- hashesToSign: HashToSign[];
684
- }>;
685
- prepareMessageForSigning(message: EVMMessage): Promise<{
686
- hashesToSign: HashToSign[];
687
- }>;
688
- prepareTypedDataForSigning(typedDataRequest: EVMTypedData): Promise<{
689
- hashesToSign: HashToSign[];
690
- }>;
691
- /**
692
- * This implementation is a common step for Biconomy and Alchemy.
693
- * Key differences between implementations:
694
- * - Signature format: Biconomy omits 0x00 prefix when concatenating, Alchemy includes it
695
- * - Version support: Biconomy only supports v6, Alchemy supports both v6 and v7
696
- * - Validation: Biconomy uses modules for signature validation, Alchemy uses built-in validation
697
- */
698
- prepareUserOpForSigning(userOp: UserOperationV7 | UserOperationV6, entryPointAddress?: Address, chainIdArgs?: number): Promise<{
699
- userOp: UserOperationV7 | UserOperationV6;
700
- hashesToSign: HashToSign[];
701
- }>;
702
- attachTransactionSignature({ transaction, rsvSignatures, }: {
703
- transaction: EVMUnsignedTransaction;
704
- rsvSignatures: RSVSignature[];
705
- }): `0x02${string}`;
706
- assembleMessageSignature({ rsvSignatures, }: {
707
- rsvSignatures: RSVSignature[];
708
- }): Hex;
709
- assembleTypedDataSignature({ rsvSignatures, }: {
710
- rsvSignatures: RSVSignature[];
711
- }): Hex;
712
- attachUserOpSignature({ userOp, rsvSignatures, }: {
713
- userOp: UserOperationV7 | UserOperationV6;
714
- rsvSignatures: RSVSignature[];
715
- }): UserOperationV7 | UserOperationV6;
716
- broadcastTx(txSerialized: `0x${string}`): Promise<Hash>;
717
- }
871
+ internalType: string;
872
+ name: string;
873
+ type: string;
874
+ })[];
875
+ internalType: string;
876
+ name: string;
877
+ type: string;
878
+ }[];
879
+ name: string;
880
+ outputs: never[];
881
+ stateMutability: string;
882
+ type: string;
883
+ anonymous?: undefined;
884
+ })[];
718
885
 
719
- interface EVMFeeProperties {
720
- gas: bigint;
721
- maxFeePerGas: bigint;
722
- maxPriorityFeePerGas: bigint;
886
+ declare const ChainSignaturesContractABI_abi: typeof abi;
887
+ declare namespace ChainSignaturesContractABI {
888
+ export { ChainSignaturesContractABI_abi as abi };
723
889
  }
724
- declare function fetchEVMFeeProperties(client: PublicClient, transaction: TransactionRequest): Promise<EVMFeeProperties>;
725
890
 
726
- declare abstract class BTCRpcAdapter {
727
- abstract selectUTXOs(from: string, targets: BTCOutput[]): Promise<{
728
- inputs: BTCInput[];
729
- outputs: BTCOutput[];
730
- }>;
731
- abstract broadcastTransaction(transactionHex: string): Promise<string>;
732
- abstract getBalance(address: string): Promise<number>;
733
- abstract getTransaction(txid: string): Promise<BTCTransaction$1>;
891
+ declare class ChainSignatureError extends Error {
892
+ requestId: `0x${string}`;
893
+ receipt: TransactionReceipt;
894
+ constructor(message: string, requestId: `0x${string}`, receipt: TransactionReceipt);
895
+ }
896
+ declare class SignatureNotFoundError extends ChainSignatureError {
897
+ constructor(requestId: `0x${string}`, receipt: TransactionReceipt);
898
+ }
899
+ declare class SignatureContractError extends ChainSignatureError {
900
+ errorCode: string;
901
+ constructor(errorCode: string, requestId: `0x${string}`, receipt: TransactionReceipt);
902
+ }
903
+ declare class SigningError extends ChainSignatureError {
904
+ originalError?: Error;
905
+ constructor(requestId: `0x${string}`, receipt: TransactionReceipt, originalError?: Error);
734
906
  }
735
907
 
736
- declare class Mempool extends BTCRpcAdapter {
737
- private readonly providerUrl;
738
- constructor(providerUrl: string);
739
- private fetchFeeRate;
740
- private fetchUTXOs;
741
- selectUTXOs(from: string, targets: BTCOutput[], confirmationTarget?: number): Promise<{
742
- inputs: BTCInput[];
743
- outputs: BTCOutput[];
744
- }>;
745
- broadcastTransaction(transactionHex: string): Promise<string>;
746
- getBalance(address: string): Promise<number>;
747
- getTransaction(txid: string): Promise<BTCTransaction$1>;
908
+ type errors_ChainSignatureError = ChainSignatureError;
909
+ declare const errors_ChainSignatureError: typeof ChainSignatureError;
910
+ type errors_SignatureContractError = SignatureContractError;
911
+ declare const errors_SignatureContractError: typeof SignatureContractError;
912
+ type errors_SignatureNotFoundError = SignatureNotFoundError;
913
+ declare const errors_SignatureNotFoundError: typeof SignatureNotFoundError;
914
+ type errors_SigningError = SigningError;
915
+ declare const errors_SigningError: typeof SigningError;
916
+ declare namespace errors {
917
+ export { errors_ChainSignatureError as ChainSignatureError, errors_SignatureContractError as SignatureContractError, errors_SignatureNotFoundError as SignatureNotFoundError, errors_SigningError as SigningError };
748
918
  }
749
919
 
750
- declare const BTCRpcAdapters: {
751
- Mempool: typeof Mempool;
752
- };
920
+ interface SignOptions {
921
+ sign: {
922
+ algo?: string;
923
+ dest?: string;
924
+ params?: string;
925
+ };
926
+ retry: {
927
+ delay?: number;
928
+ retryCount?: number;
929
+ };
930
+ }
931
+ interface SignatureErrorData {
932
+ requestId: string;
933
+ responder: string;
934
+ error: string;
935
+ }
936
+ interface RequestIdArgs {
937
+ address: Address;
938
+ payload: Hex;
939
+ path: string;
940
+ keyVersion: number;
941
+ chainId: bigint;
942
+ algo: string;
943
+ dest: string;
944
+ params: string;
945
+ }
753
946
 
754
947
  /**
755
- * Implementation of the Chain interface for Bitcoin network.
756
- * Handles interactions with both Bitcoin mainnet and testnet, supporting P2WPKH transactions.
948
+ * Implementation of the ChainSignatureContract for EVM chains.
949
+ *
950
+ * When signing data, the contract emits a SignatureRequested event with a requestId.
951
+ * This requestId is used to track the signature request and retrieve the signature
952
+ * once it's available. The sign method handles this process automatically by polling
953
+ * for the signature using the requestId.
757
954
  */
758
- declare class Bitcoin extends Chain<BTCTransactionRequest, BTCUnsignedTransaction> {
759
- private static readonly SATOSHIS_PER_BTC;
760
- private readonly network;
761
- private readonly btcRpcAdapter;
762
- private readonly contract;
955
+ declare class ChainSignatureContract extends ChainSignatureContract$2 {
956
+ private readonly publicClient;
957
+ private readonly walletClient;
958
+ private readonly contractAddress;
959
+ private readonly rootPublicKey;
763
960
  /**
764
- * Creates a new Bitcoin chain instance
765
- * @param params - Configuration parameters
766
- * @param params.network - Network identifier (mainnet/testnet)
767
- * @param params.contract - Instance of the chain signature contract for MPC operations
768
- * @param params.btcRpcAdapter - Bitcoin RPC adapter for network interactions
961
+ * Creates a new instance of the ChainSignatureContract for EVM chains.
962
+ *
963
+ * @param args - Configuration options for the contract
964
+ * @param args.publicClient - A Viem PublicClient instance for reading from the blockchain
965
+ * @param args.walletClient - A Viem WalletClient instance for sending transactions
966
+ * @param args.contractAddress - The address of the deployed ChainSignatures contract (e.g. `0x857ED3A242B59cC24144814a0DF41C397a3811E6`)
967
+ * @param args.rootPublicKey - Optional root public key. If not provided, it will be derived from the contract address
769
968
  */
770
- constructor({ network, contract, btcRpcAdapter, }: {
771
- network: BTCNetworkIds;
772
- contract: BaseChainSignatureContract;
773
- btcRpcAdapter: BTCRpcAdapter;
969
+ constructor(args: {
970
+ publicClient: PublicClient;
971
+ walletClient: WalletClient;
972
+ contractAddress: Hex;
973
+ rootPublicKey?: NajPublicKey;
774
974
  });
975
+ getCurrentSignatureDeposit(): Promise<BN>;
976
+ getDerivedPublicKey(args: {
977
+ path: string;
978
+ predecessor: string;
979
+ }): Promise<UncompressedPubKeySEC1>;
980
+ getPublicKey(): Promise<UncompressedPubKeySEC1>;
981
+ getLatestKeyVersion(): Promise<number>;
775
982
  /**
776
- * Converts satoshis to BTC
777
- * @param satoshis - Amount in satoshis
778
- * @returns Amount in BTC
779
- */
780
- static toBTC(satoshis: number): number;
781
- /**
782
- * Converts BTC to satoshis
783
- * @param btc - Amount in BTC
784
- * @returns Amount in satoshis (rounded)
983
+ * Sends a transaction to the contract to request a signature, then
984
+ * polls for the signature result. If the signature is not found within the retry
985
+ * parameters, it will throw an error.
785
986
  */
786
- static toSatoshi(btc: number): number;
787
- private fetchTransaction;
788
- private static transformRSVSignature;
987
+ sign(args: SignArgs, options?: SignOptions): Promise<RSVSignature>;
789
988
  /**
790
- * Creates a Partially Signed Bitcoin Transaction (PSBT)
791
- * @param params - Parameters for creating the PSBT
792
- * @param params.transactionRequest - Transaction request containing inputs and outputs
793
- * @returns Created PSBT instance
989
+ * Generates the request ID for a signature request allowing to track the response.
990
+ *
991
+ * @param request - The signature request object containing:
992
+ * @param request.address - The contract/wallet address calling the signing contract
993
+ * @param request.payload - The data payload to be signed as a hex string
994
+ * @param request.path - The derivation path for the key
995
+ * @param request.keyVersion - The version of the key to use
996
+ * @param request.chainId - The chain ID as a bigint
997
+ * @param request.algo - The signing algorithm to use
998
+ * @param request.dest - The destination for the signature
999
+ * @param request.params - Additional parameters for the signing process
1000
+ * @returns A hex string representing the unique request ID
1001
+ *
1002
+ * @example
1003
+ * ```typescript
1004
+ * const requestId = ChainSignatureContract.getRequestId({
1005
+ * address: walletClient.account.address,
1006
+ * payload: payload: `0x${Buffer.from(args.payload).toString('hex')}`,,
1007
+ * path: '',
1008
+ * keyVersion: 0,
1009
+ * chainId: 1n,
1010
+ * algo: '',
1011
+ * dest: '',
1012
+ * params: ''
1013
+ * });
1014
+ * console.log(requestId); // 0x...
1015
+ * ```
794
1016
  */
795
- createPSBT({ transactionRequest, }: {
796
- transactionRequest: BTCTransactionRequest;
797
- }): Promise<bitcoin.Psbt>;
798
- getBalance(address: string): Promise<{
799
- balance: bigint;
800
- decimals: number;
801
- }>;
802
- deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
803
- address: string;
804
- publicKey: string;
805
- }>;
806
- serializeTransaction(transaction: BTCUnsignedTransaction): string;
807
- deserializeTransaction(serialized: string): BTCUnsignedTransaction;
808
- prepareTransactionForSigning(transactionRequest: BTCTransactionRequest): Promise<{
809
- transaction: BTCUnsignedTransaction;
810
- hashesToSign: HashToSign[];
811
- }>;
812
- attachTransactionSignature({ transaction: { psbt, publicKey }, rsvSignatures, }: {
813
- transaction: BTCUnsignedTransaction;
814
- rsvSignatures: RSVSignature[];
815
- }): string;
816
- broadcastTx(txSerialized: string): Promise<string>;
817
- }
818
-
819
- /**
820
- * Implementation of the Chain interface for Cosmos-based networks.
821
- * Handles interactions with Cosmos SDK chains like Cosmos Hub, Osmosis, etc.
822
- */
823
- declare class Cosmos extends Chain<CosmosTransactionRequest, CosmosUnsignedTransaction> {
824
- private readonly registry;
825
- private readonly chainId;
826
- private readonly contract;
827
- private readonly endpoints?;
1017
+ getRequestId(request: RequestIdArgs): Hex;
1018
+ getErrorFromEvents(requestId: Hex, fromBlock: bigint): Promise<SignatureErrorData | undefined>;
828
1019
  /**
829
- * Creates a new Cosmos chain instance
830
- * @param params - Configuration parameters
831
- * @param params.chainId - Chain id for the Cosmos network
832
- * @param params.contract - Instance of the chain signature contract for MPC operations
833
- * @param params.endpoints - Optional RPC and REST endpoints
834
- * @param params.endpoints.rpcUrl - Optional RPC endpoint URL
835
- * @param params.endpoints.restUrl - Optional REST endpoint URL
1020
+ * Searches for SignatureResponded events that match the given requestId.
1021
+ * It works in conjunction with the getRequestId method which generates the unique
1022
+ * identifier for a signature request.
1023
+ *
1024
+ * @param requestId - The identifier for the signature request
1025
+ * @param fromBlock - The block number to start searching from
1026
+ * @returns The RSV signature if found, undefined otherwise
836
1027
  */
837
- constructor({ chainId, contract, endpoints, }: {
838
- contract: BaseChainSignatureContract;
839
- chainId: CosmosNetworkIds;
840
- endpoints?: {
841
- rpcUrl?: string;
842
- restUrl?: string;
843
- };
844
- });
845
- private transformRSVSignature;
846
- private getChainInfo;
847
- getBalance(address: string): Promise<{
848
- balance: bigint;
849
- decimals: number;
850
- }>;
851
- deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
852
- address: string;
853
- publicKey: string;
854
- }>;
855
- serializeTransaction(transaction: CosmosUnsignedTransaction): string;
856
- deserializeTransaction(serialized: string): CosmosUnsignedTransaction;
857
- prepareTransactionForSigning(transactionRequest: CosmosTransactionRequest): Promise<{
858
- transaction: CosmosUnsignedTransaction;
859
- hashesToSign: HashToSign[];
860
- }>;
861
- attachTransactionSignature({ transaction, rsvSignatures, }: {
862
- transaction: CosmosUnsignedTransaction;
863
- rsvSignatures: RSVSignature[];
864
- }): string;
865
- broadcastTx(txSerialized: string): Promise<string>;
1028
+ getSignatureFromEvents(requestId: Hex, fromBlock: bigint): Promise<RSVSignature | undefined>;
866
1029
  }
867
1030
 
868
- declare const ENVS: {
869
- readonly TESTNET_DEV: "TESTNET_DEV";
870
- readonly TESTNET: "TESTNET";
871
- readonly MAINNET: "MAINNET";
872
- };
873
- declare const CHAINS: {
874
- readonly ETHEREUM: "ETHEREUM";
875
- readonly NEAR: "NEAR";
876
- };
877
- /**
878
- * Root public keys for the Sig Network Smart Contracts across different environments.
879
- *
880
- * These keys should never change.
881
- */
882
- declare const ROOT_PUBLIC_KEYS: Record<keyof typeof ENVS, NajPublicKey>;
883
- /**
884
- * Chain IDs used in the key derivation function (KDF) for deriving child public keys to
885
- * distinguish between different chains.
886
- *
887
- * @see {@link deriveChildPublicKey} in cryptography.ts for usage details
888
- */
889
- declare const KDF_CHAIN_IDS: {
890
- readonly ETHEREUM: "0x1";
891
- readonly NEAR: "0x18d";
1031
+ declare const utils: {
1032
+ ChainSignaturesContractABI: typeof ChainSignaturesContractABI;
1033
+ errors: typeof errors;
892
1034
  };
893
- /**
894
- * Contract addresses for different chains and environments.
895
- *
896
- * - Testnet Dev: Used for internal development, very unstable
897
- * - Testnet: Used for external development, stable
898
- * - Mainnet: Production contract address
899
- *
900
- * @see ChainSignatureContract documentation for implementation details
901
- */
902
- declare const CONTRACT_ADDRESSES: Record<keyof typeof CHAINS, Record<keyof typeof ENVS, string>>;
903
1035
 
904
- declare const constants_CHAINS: typeof CHAINS;
905
- declare const constants_CONTRACT_ADDRESSES: typeof CONTRACT_ADDRESSES;
906
- declare const constants_ENVS: typeof ENVS;
907
- declare const constants_KDF_CHAIN_IDS: typeof KDF_CHAIN_IDS;
908
- declare const constants_ROOT_PUBLIC_KEYS: typeof ROOT_PUBLIC_KEYS;
909
- declare namespace constants {
910
- export { constants_CHAINS as CHAINS, constants_CONTRACT_ADDRESSES as CONTRACT_ADDRESSES, constants_ENVS as ENVS, constants_KDF_CHAIN_IDS as KDF_CHAIN_IDS, constants_ROOT_PUBLIC_KEYS as ROOT_PUBLIC_KEYS };
1036
+ type index$1_ChainSignatureContract = ChainSignatureContract;
1037
+ declare const index$1_ChainSignatureContract: typeof ChainSignatureContract;
1038
+ declare const index$1_utils: typeof utils;
1039
+ declare namespace index$1 {
1040
+ export { index$1_ChainSignatureContract as ChainSignatureContract, index$1_utils as utils };
911
1041
  }
912
1042
 
913
- declare const index_constants: typeof constants;
914
- declare const index_cryptography: typeof cryptography;
1043
+ type index_SignArgs = SignArgs;
915
1044
  declare namespace index {
916
- export { index$1 as chains, index_constants as constants, index_cryptography as cryptography };
1045
+ export { ChainSignatureContract$2 as ChainSignatureContract, type index_SignArgs as SignArgs, index$1 as evm, index$2 as near };
917
1046
  }
918
1047
 
919
- export { type BTCInput, type BTCNetworkIds, type BTCOutput, BTCRpcAdapter, BTCRpcAdapters, type BTCTransaction$1 as BTCTransaction, type BTCTransactionRequest, type BTCUnsignedTransaction, Bitcoin, Chain, ChainSignatureContract$2 as ChainSignatureContract, type CompressedPubKeySEC1, Cosmos, type CosmosNetworkIds, type CosmosTransactionRequest, type CosmosUnsignedTransaction, EVM, type EVMMessage, type EVMTransactionRequest, type EVMTypedData, type EVMUnsignedTransaction, type HashToSign, type KeyDerivationPath, type MPCSignature, type NajPublicKey, type NearNearMpcSignature, type RSVSignature, type SigNetEvmMpcSignature, type SigNetNearMpcSignature, type SignArgs, type UncompressedPubKeySEC1, fetchEVMFeeProperties, index as utils };
1048
+ export { type CompressedPubKeySEC1, type HashToSign, type KeyDerivationPath, type MPCSignature, type NajPublicKey, type NearNearMpcSignature, type RSVSignature, type SigNetEvmMpcSignature, type SigNetNearMpcSignature, type UncompressedPubKeySEC1, index$3 as chainAdapters, constants, index as contracts, index$7 as utils };