signet.js 0.0.2-beta.6 → 0.0.3

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.
Files changed (71) hide show
  1. package/.eslintrc.json +55 -0
  2. package/.prettierrc +1 -0
  3. package/babel.config.js +6 -0
  4. package/docs/pages/index.mdx +36 -0
  5. package/docs/pages/signetjs/advanced/chain-signatures-contract.mdx +52 -0
  6. package/docs/pages/signetjs/advanced/chain.mdx +45 -0
  7. package/docs/pages/signetjs/chains/bitcoin/bitcoin.mdx +171 -0
  8. package/docs/pages/signetjs/chains/bitcoin/btc-rpc-adapter.mdx +26 -0
  9. package/docs/pages/signetjs/chains/cosmos.mdx +171 -0
  10. package/docs/pages/signetjs/chains/evm.mdx +319 -0
  11. package/docs/pages/signetjs/contract-addresses.mdx +27 -0
  12. package/docs/pages/signetjs/index.mdx +88 -0
  13. package/docs/snippets/code/contract.ts +21 -0
  14. package/docs/snippets/code/evm/env.ts +16 -0
  15. package/docs/snippets/code/near/env.ts +13 -0
  16. package/hardhat.config.mts +19 -0
  17. package/package.json +1 -1
  18. package/src/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.ts +11 -0
  19. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.ts +96 -0
  20. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/index.ts +1 -0
  21. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/types.ts +72 -0
  22. package/src/chains/Bitcoin/BTCRpcAdapter/index.ts +6 -0
  23. package/src/chains/Bitcoin/Bitcoin.ts +287 -0
  24. package/src/chains/Bitcoin/types.ts +48 -0
  25. package/src/chains/Bitcoin/utils.ts +14 -0
  26. package/src/chains/Chain.ts +92 -0
  27. package/src/chains/ChainSignatureContract.ts +65 -0
  28. package/src/chains/Cosmos/Cosmos.ts +258 -0
  29. package/src/chains/Cosmos/types.ts +35 -0
  30. package/src/chains/Cosmos/utils.ts +45 -0
  31. package/src/chains/EVM/EVM.test.ts +238 -0
  32. package/src/chains/EVM/EVM.ts +334 -0
  33. package/src/chains/EVM/types.ts +53 -0
  34. package/src/chains/EVM/utils.ts +27 -0
  35. package/src/chains/index.ts +38 -0
  36. package/src/chains/types.ts +46 -0
  37. package/src/index.ts +2 -0
  38. package/src/utils/chains/evm/ChainSignaturesContract.ts +286 -0
  39. package/src/utils/chains/evm/ChainSignaturesContractABI.ts +359 -0
  40. package/src/utils/chains/evm/errors.ts +52 -0
  41. package/src/utils/chains/evm/index.ts +3 -0
  42. package/src/utils/chains/evm/types.ts +28 -0
  43. package/src/utils/chains/evm/utils.ts +11 -0
  44. package/src/utils/chains/index.ts +2 -0
  45. package/src/utils/chains/near/ChainSignatureContract.ts +155 -0
  46. package/src/utils/chains/near/account.ts +42 -0
  47. package/src/utils/chains/near/constants.ts +4 -0
  48. package/src/utils/chains/near/index.ts +3 -0
  49. package/src/utils/chains/near/signAndSend/index.ts +1 -0
  50. package/src/utils/chains/near/signAndSend/keypair.ts +178 -0
  51. package/src/utils/chains/near/transactionBuilder.ts +73 -0
  52. package/src/utils/chains/near/types.ts +77 -0
  53. package/src/utils/constants.ts +62 -0
  54. package/src/utils/cryptography.ts +131 -0
  55. package/src/utils/index.ts +3 -0
  56. package/src/utils/publicKey.ts +23 -0
  57. package/tsconfig.eslint.json +8 -0
  58. package/tsconfig.json +122 -0
  59. package/tsup.config.ts +55 -0
  60. package/vitest.config.ts +16 -0
  61. package/vocs.config.ts +73 -0
  62. package/browser/index.browser.cjs +0 -3
  63. package/browser/index.browser.cjs.map +0 -1
  64. package/browser/index.browser.js +0 -3
  65. package/browser/index.browser.js.map +0 -1
  66. package/node/index.node.cjs +0 -3
  67. package/node/index.node.cjs.map +0 -1
  68. package/node/index.node.js +0 -3
  69. package/node/index.node.js.map +0 -1
  70. package/types/index.d.cts +0 -919
  71. package/types/index.d.ts +0 -919
package/types/index.d.ts DELETED
@@ -1,919 +0,0 @@
1
- import { NetworkId, Action, FinalExecutionOutcome } from '@near-wallet-selector/core';
2
- import BN from 'bn.js';
3
- import * as bitcoin from 'bitcoinjs-lib';
4
- import { EncodeObject } from '@cosmjs/proto-signing';
5
- import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
6
- import { TransactionRequest, Address, SignableMessage, TypedDataDefinition, Hex, PublicClient, WalletClient, TransactionReceipt, Hash } from 'viem';
7
- import { KeyPair } from '@near-js/crypto';
8
-
9
- interface SignArgs {
10
- /** The payload to sign as an array of 32 bytes */
11
- payload: number[];
12
- /** The derivation path for key generation */
13
- path: string;
14
- /** Version of the key to use */
15
- key_version: number;
16
- }
17
- /**
18
- * Base contract interface required for compatibility with Chain instances like EVM and Bitcoin.
19
- *
20
- * See {@link EVM} and {@link Bitcoin} for example implementations.
21
- */
22
- declare abstract class BaseChainSignatureContract {
23
- /**
24
- * Gets the current signature deposit required by the contract.
25
- * This deposit amount helps manage network congestion.
26
- *
27
- * @returns Promise resolving to the required deposit amount as a BigNumber
28
- */
29
- abstract getCurrentSignatureDeposit(): Promise<BN>;
30
- /**
31
- * Derives a child public key using a\ derivation path and predecessor.
32
- *
33
- * @param args - Arguments for key derivation
34
- * @param args.path - The string path to use derive the key
35
- * @param args.predecessor - The id/address of the account requesting signature
36
- * @returns Promise resolving to the derived SEC1 uncompressed public key
37
- */
38
- abstract getDerivedPublicKey(args: {
39
- path: string;
40
- predecessor: string;
41
- } & Record<string, unknown>): Promise<UncompressedPubKeySEC1>;
42
- }
43
- /**
44
- * Full contract interface that extends BaseChainSignatureContract to provide all Sig Network Smart Contract capabilities.
45
- */
46
- declare abstract class ChainSignatureContract$2 extends BaseChainSignatureContract {
47
- /**
48
- * Signs a payload using Sig Network MPC.
49
- *
50
- * @param args - Arguments for the signing operation
51
- * @param args.payload - The data to sign as an array of 32 bytes
52
- * @param args.path - The string path to use derive the key
53
- * @param args.key_version - Version of the key to use
54
- * @returns Promise resolving to the RSV signature
55
- */
56
- abstract sign(args: SignArgs & Record<string, unknown>): Promise<RSVSignature>;
57
- /**
58
- * Gets the public key associated with this contract instance.
59
- *
60
- * @returns Promise resolving to the SEC1 uncompressed public key
61
- */
62
- abstract getPublicKey(): Promise<UncompressedPubKeySEC1>;
63
- }
64
-
65
- type HashToSign = SignArgs['payload'];
66
- type Base58String = string;
67
- type NajPublicKey = `secp256k1:${Base58String}`;
68
- type UncompressedPubKeySEC1 = `04${string}`;
69
- type CompressedPubKeySEC1 = `02${string}` | `03${string}`;
70
- type KeyDerivationPath = string;
71
- interface RSVSignature {
72
- r: string;
73
- s: string;
74
- v: number;
75
- }
76
- interface NearNearMpcSignature {
77
- big_r: {
78
- affine_point: string;
79
- };
80
- s: {
81
- scalar: string;
82
- };
83
- recovery_id: number;
84
- }
85
- interface SigNetNearMpcSignature {
86
- big_r: string;
87
- s: string;
88
- recovery_id: number;
89
- }
90
- interface SigNetEvmMpcSignature {
91
- bigR: {
92
- x: bigint;
93
- y: bigint;
94
- };
95
- s: bigint;
96
- recoveryId: number;
97
- }
98
- type MPCSignature = NearNearMpcSignature | SigNetNearMpcSignature | SigNetEvmMpcSignature;
99
-
100
- interface BTCTransaction$1 {
101
- vout: Array<{
102
- scriptpubkey: string;
103
- value: number;
104
- }>;
105
- }
106
- interface BTCInput {
107
- txid: string;
108
- vout: number;
109
- value: number;
110
- scriptPubKey: Buffer;
111
- }
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;
139
- }
140
- type BTCNetworkIds = 'mainnet' | 'testnet' | 'regtest';
141
-
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;
150
- }
151
-
152
- type EVMUnsignedTransaction = TransactionRequest & {
153
- type: 'eip1559';
154
- chainId: number;
155
- };
156
- interface EVMTransactionRequest extends Omit<EVMUnsignedTransaction, 'chainId' | 'type'> {
157
- from: Address;
158
- }
159
- type EVMMessage = SignableMessage;
160
- type EVMTypedData = TypedDataDefinition;
161
- interface UserOperationV7 {
162
- sender: Hex;
163
- nonce: Hex;
164
- factory: Hex;
165
- factoryData: Hex;
166
- callData: Hex;
167
- callGasLimit: Hex;
168
- verificationGasLimit: Hex;
169
- preVerificationGas: Hex;
170
- maxFeePerGas: Hex;
171
- maxPriorityFeePerGas: Hex;
172
- paymaster: Hex;
173
- paymasterVerificationGasLimit: Hex;
174
- paymasterPostOpGasLimit: Hex;
175
- paymasterData: Hex;
176
- signature: Hex;
177
- }
178
- interface UserOperationV6 {
179
- sender: Hex;
180
- nonce: Hex;
181
- initCode: Hex;
182
- callData: Hex;
183
- callGasLimit: Hex;
184
- verificationGasLimit: Hex;
185
- preVerificationGas: Hex;
186
- maxFeePerGas: Hex;
187
- maxPriorityFeePerGas: Hex;
188
- paymasterAndData: Hex;
189
- signature: Hex;
190
- }
191
-
192
- /**
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;
259
-
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 };
264
- }
265
-
266
- declare const EVMTransaction: (req: EVMRequest, keyPair: KeyPair) => Promise<Response>;
267
- declare const BTCTransaction: (req: BitcoinRequest, keyPair: KeyPair) => Promise<Response>;
268
- declare const CosmosTransaction: (req: CosmosRequest, keyPair: KeyPair) => Promise<Response>;
269
-
270
- declare const keypair_BTCTransaction: typeof BTCTransaction;
271
- declare const keypair_CosmosTransaction: typeof CosmosTransaction;
272
- declare const keypair_EVMTransaction: typeof EVMTransaction;
273
- declare namespace keypair {
274
- export { keypair_BTCTransaction as BTCTransaction, keypair_CosmosTransaction as CosmosTransaction, keypair_EVMTransaction as EVMTransaction };
275
- }
276
-
277
- declare const index$4_keypair: typeof keypair;
278
- declare namespace index$4 {
279
- export { index$4_keypair as keypair };
280
- }
281
-
282
- interface ChainSignatureContractArgs {
283
- networkId: NearNetworkIds;
284
- contractId: ChainSignatureContractIds;
285
- accountId?: string;
286
- keypair?: KeyPair;
287
- }
288
- /**
289
- * Implementation of the ChainSignatureContract for NEAR chains.
290
- *
291
- * This class provides an interface to interact with the ChainSignatures contract
292
- * deployed on NEAR. It supports both view methods (which don't require authentication)
293
- * and change methods (which require a valid NEAR account and keypair).
294
- *
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;
357
- /**
358
- * Creates a new instance of the ChainSignatureContract for EVM chains.
359
- *
360
- * @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
365
- */
366
- constructor(args: {
367
- publicClient: PublicClient;
368
- walletClient: WalletClient;
369
- contractAddress: Hex;
370
- rootPublicKey?: NajPublicKey;
371
- });
372
- getCurrentSignatureDeposit(): Promise<BN>;
373
- getDerivedPublicKey(args: {
374
- path: string;
375
- predecessor: string;
376
- }): Promise<UncompressedPubKeySEC1>;
377
- 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>;
383
- }
384
-
385
- declare const abi: ({
386
- inputs: {
387
- internalType: string;
388
- name: string;
389
- type: string;
390
- }[];
391
- stateMutability: string;
392
- type: string;
393
- name?: undefined;
394
- anonymous?: undefined;
395
- outputs?: undefined;
396
- } | {
397
- inputs: {
398
- internalType: string;
399
- name: string;
400
- type: string;
401
- }[];
402
- name: string;
403
- type: string;
404
- stateMutability?: undefined;
405
- anonymous?: undefined;
406
- outputs?: undefined;
407
- } | {
408
- anonymous: boolean;
409
- inputs: ({
410
- indexed: boolean;
411
- internalType: string;
412
- name: string;
413
- type: string;
414
- components?: undefined;
415
- } | {
416
- components: ({
417
- components: {
418
- internalType: string;
419
- name: string;
420
- type: string;
421
- }[];
422
- internalType: string;
423
- name: string;
424
- type: string;
425
- } | {
426
- internalType: string;
427
- name: string;
428
- type: string;
429
- components?: undefined;
430
- })[];
431
- indexed: boolean;
432
- internalType: string;
433
- name: string;
434
- type: string;
435
- })[];
436
- name: string;
437
- type: string;
438
- stateMutability?: undefined;
439
- outputs?: undefined;
440
- } | {
441
- inputs: {
442
- internalType: string;
443
- name: string;
444
- type: string;
445
- }[];
446
- name: string;
447
- outputs: {
448
- internalType: string;
449
- name: string;
450
- type: string;
451
- }[];
452
- stateMutability: string;
453
- type: string;
454
- anonymous?: undefined;
455
- } | {
456
- inputs: {
457
- components: ({
458
- internalType: string;
459
- name: string;
460
- type: string;
461
- components?: undefined;
462
- } | {
463
- components: ({
464
- components: {
465
- internalType: string;
466
- name: string;
467
- type: string;
468
- }[];
469
- internalType: string;
470
- name: string;
471
- type: string;
472
- } | {
473
- internalType: string;
474
- name: string;
475
- type: string;
476
- components?: undefined;
477
- })[];
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
- }
718
-
719
- interface EVMFeeProperties {
720
- gas: bigint;
721
- maxFeePerGas: bigint;
722
- maxPriorityFeePerGas: bigint;
723
- }
724
- declare function fetchEVMFeeProperties(client: PublicClient, transaction: TransactionRequest): Promise<EVMFeeProperties>;
725
-
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>;
734
- }
735
-
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>;
748
- }
749
-
750
- declare const BTCRpcAdapters: {
751
- Mempool: typeof Mempool;
752
- };
753
-
754
- /**
755
- * Implementation of the Chain interface for Bitcoin network.
756
- * Handles interactions with both Bitcoin mainnet and testnet, supporting P2WPKH transactions.
757
- */
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;
763
- /**
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
769
- */
770
- constructor({ network, contract, btcRpcAdapter, }: {
771
- network: BTCNetworkIds;
772
- contract: BaseChainSignatureContract;
773
- btcRpcAdapter: BTCRpcAdapter;
774
- });
775
- /**
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)
785
- */
786
- static toSatoshi(btc: number): number;
787
- private fetchTransaction;
788
- private static transformRSVSignature;
789
- /**
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
794
- */
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?;
828
- /**
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
836
- */
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>;
866
- }
867
-
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";
892
- };
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
-
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 };
911
- }
912
-
913
- declare const index_constants: typeof constants;
914
- declare const index_cryptography: typeof cryptography;
915
- declare namespace index {
916
- export { index$1 as chains, index_constants as constants, index_cryptography as cryptography };
917
- }
918
-
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 };