signet.js 0.0.2-beta.4 → 0.0.2-beta.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signet.js",
3
- "version": "0.0.2-beta.4",
3
+ "version": "0.0.2-beta.5",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -26,7 +26,7 @@
26
26
  "build": "rm -rf dist && npm run build:browser && npm run build:node && npm run build:post && cp package.json README.md LICENSE dist/",
27
27
  "build:browser": "tsup --env.TARGET=browser",
28
28
  "build:node": "tsup --env.TARGET=node",
29
- "build:post": "mkdir -p dist/types && cp dist/node/index.d.ts dist/node/index.d.cts dist/types/",
29
+ "build:post": "mkdir -p dist/types && cp dist/node/index.d.ts dist/node/index.d.cts dist/types/ && rm dist/node/index.d.ts dist/node/index.d.cts",
30
30
  "pre:deploy": "npm run build && npm run docs:build",
31
31
  "publish-npm": "npm run pre:deploy && npm publish",
32
32
  "publish-npm:beta": "npm run pre:deploy && cd dist && npm publish --tag beta",
package/node/index.d.cts DELETED
@@ -1,693 +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 MPCPayloads = Array<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 OldMpcSignature {
77
- big_r: {
78
- affine_point: string;
79
- };
80
- s: {
81
- scalar: string;
82
- };
83
- recovery_id: number;
84
- }
85
- interface NewMpcSignature {
86
- big_r: string;
87
- s: string;
88
- recovery_id: number;
89
- }
90
- type MPCSignature = OldMpcSignature | NewMpcSignature;
91
-
92
- interface BTCTransaction$1 {
93
- vout: Array<{
94
- scriptpubkey: string;
95
- value: number;
96
- }>;
97
- }
98
- interface BTCInput {
99
- txid: string;
100
- vout: number;
101
- value: number;
102
- scriptPubKey: Buffer;
103
- }
104
- type BTCOutput = {
105
- value: number;
106
- } | {
107
- address: string;
108
- value: number;
109
- } | {
110
- script: Buffer;
111
- value: number;
112
- };
113
- type BTCTransactionRequest = {
114
- publicKey: string;
115
- } & ({
116
- inputs: BTCInput[];
117
- outputs: BTCOutput[];
118
- from?: never;
119
- to?: never;
120
- value?: never;
121
- } | {
122
- inputs?: never;
123
- outputs?: never;
124
- from: string;
125
- to: string;
126
- value: string;
127
- });
128
- interface BTCUnsignedTransaction {
129
- psbt: bitcoin.Psbt;
130
- publicKey: string;
131
- }
132
- type BTCNetworkIds = 'mainnet' | 'testnet' | 'regtest';
133
-
134
- type CosmosNetworkIds = string;
135
- type CosmosUnsignedTransaction = TxRaw;
136
- interface CosmosTransactionRequest {
137
- address: string;
138
- publicKey: string;
139
- messages: EncodeObject[];
140
- memo?: string;
141
- gas?: number;
142
- }
143
-
144
- type EVMUnsignedTransaction = TransactionRequest & {
145
- type: 'eip1559';
146
- chainId: number;
147
- };
148
- interface EVMTransactionRequest extends Omit<EVMUnsignedTransaction, 'chainId' | 'type'> {
149
- from: Address;
150
- }
151
- type EVMMessage = SignableMessage;
152
- type EVMTypedData = TypedDataDefinition;
153
- interface UserOperationV7 {
154
- sender: Hex;
155
- nonce: Hex;
156
- factory: Hex;
157
- factoryData: Hex;
158
- callData: Hex;
159
- callGasLimit: Hex;
160
- verificationGasLimit: Hex;
161
- preVerificationGas: Hex;
162
- maxFeePerGas: Hex;
163
- maxPriorityFeePerGas: Hex;
164
- paymaster: Hex;
165
- paymasterVerificationGasLimit: Hex;
166
- paymasterPostOpGasLimit: Hex;
167
- paymasterData: Hex;
168
- signature: Hex;
169
- }
170
- interface UserOperationV6 {
171
- sender: Hex;
172
- nonce: Hex;
173
- initCode: Hex;
174
- callData: Hex;
175
- callGasLimit: Hex;
176
- verificationGasLimit: Hex;
177
- preVerificationGas: Hex;
178
- maxFeePerGas: Hex;
179
- maxPriorityFeePerGas: Hex;
180
- paymasterAndData: Hex;
181
- signature: Hex;
182
- }
183
-
184
- /**
185
- Available ChainSignature contracts:
186
- - Mainnet: v1.signer
187
- - Testnet: v1.signer-prod.testnet
188
- - Development (unstable): v1.signer-dev.testnet
189
- */
190
- type ChainSignatureContractIds = string;
191
- type NearNetworkIds = 'mainnet' | 'testnet';
192
- interface ChainProvider {
193
- providerUrl: string;
194
- contract: ChainSignatureContractIds;
195
- }
196
- interface NearAuthentication {
197
- networkId: NearNetworkIds;
198
- accountId: string;
199
- }
200
- interface SuccessResponse {
201
- transactionHash: string;
202
- success: true;
203
- }
204
- interface FailureResponse {
205
- success: false;
206
- errorMessage: string;
207
- }
208
- type Response = SuccessResponse | FailureResponse;
209
- type EVMChainConfigWithProviders = ChainProvider;
210
- interface EVMRequest {
211
- transaction: EVMTransactionRequest;
212
- chainConfig: EVMChainConfigWithProviders;
213
- nearAuthentication: NearAuthentication;
214
- fastAuthRelayerUrl?: string;
215
- derivationPath: KeyDerivationPath;
216
- }
217
- type BTCChainConfigWithProviders = ChainProvider & {
218
- network: BTCNetworkIds;
219
- };
220
- interface BitcoinRequest {
221
- transaction: BTCTransactionRequest;
222
- chainConfig: BTCChainConfigWithProviders;
223
- nearAuthentication: NearAuthentication;
224
- fastAuthRelayerUrl?: string;
225
- derivationPath: KeyDerivationPath;
226
- }
227
- interface CosmosChainConfig {
228
- contract: ChainSignatureContractIds;
229
- chainId: CosmosNetworkIds;
230
- }
231
- interface CosmosRequest {
232
- chainConfig: CosmosChainConfig;
233
- transaction: CosmosTransactionRequest;
234
- nearAuthentication: NearAuthentication;
235
- derivationPath: KeyDerivationPath;
236
- fastAuthRelayerUrl?: string;
237
- }
238
-
239
- declare const mpcPayloadsToChainSigTransaction: ({ networkId, contractId, mpcPayloads, path, }: {
240
- networkId: NetworkId;
241
- contractId: ChainSignatureContractIds;
242
- mpcPayloads: MPCPayloads;
243
- path: KeyDerivationPath;
244
- }) => Promise<{
245
- receiverId: string;
246
- actions: Action[];
247
- }>;
248
- declare const responseToMpcSignature: ({ response, }: {
249
- response: FinalExecutionOutcome;
250
- }) => RSVSignature | undefined;
251
-
252
- declare const transactionBuilder_mpcPayloadsToChainSigTransaction: typeof mpcPayloadsToChainSigTransaction;
253
- declare const transactionBuilder_responseToMpcSignature: typeof responseToMpcSignature;
254
- declare namespace transactionBuilder {
255
- export { transactionBuilder_mpcPayloadsToChainSigTransaction as mpcPayloadsToChainSigTransaction, transactionBuilder_responseToMpcSignature as responseToMpcSignature };
256
- }
257
-
258
- declare const EVMTransaction: (req: EVMRequest, keyPair: KeyPair) => Promise<Response>;
259
- declare const BTCTransaction: (req: BitcoinRequest, keyPair: KeyPair) => Promise<Response>;
260
- declare const CosmosTransaction: (req: CosmosRequest, keyPair: KeyPair) => Promise<Response>;
261
-
262
- declare const keypair_BTCTransaction: typeof BTCTransaction;
263
- declare const keypair_CosmosTransaction: typeof CosmosTransaction;
264
- declare const keypair_EVMTransaction: typeof EVMTransaction;
265
- declare namespace keypair {
266
- export { keypair_BTCTransaction as BTCTransaction, keypair_CosmosTransaction as CosmosTransaction, keypair_EVMTransaction as EVMTransaction };
267
- }
268
-
269
- declare const index$4_keypair: typeof keypair;
270
- declare namespace index$4 {
271
- export { index$4_keypair as keypair };
272
- }
273
-
274
- interface ChainSignatureContractArgs$1 {
275
- networkId: NearNetworkIds;
276
- contractId: ChainSignatureContractIds;
277
- accountId?: string;
278
- keypair?: KeyPair;
279
- }
280
- /**
281
- * This contract will default to view methods only.
282
- * If you want to use the change methods, you need to provide an account and keypair.
283
- */
284
- declare class ChainSignatureContract$1 extends ChainSignatureContract$2 {
285
- private readonly networkId;
286
- private readonly contractId;
287
- private readonly accountId;
288
- private readonly keypair;
289
- constructor({ networkId, contractId, accountId, keypair, }: ChainSignatureContractArgs$1);
290
- private getContract;
291
- getCurrentSignatureDeposit(): Promise<BN>;
292
- getDerivedPublicKey(args: {
293
- path: string;
294
- predecessor: string;
295
- }): Promise<UncompressedPubKeySEC1>;
296
- getPublicKey(): Promise<UncompressedPubKeySEC1>;
297
- sign(args: SignArgs): Promise<RSVSignature>;
298
- }
299
-
300
- declare const index$3_transactionBuilder: typeof transactionBuilder;
301
- declare namespace index$3 {
302
- export { ChainSignatureContract$1 as ChainSignatureContract, index$4 as signAndSend, index$3_transactionBuilder as transactionBuilder };
303
- }
304
-
305
- interface ChainSignatureContractArgs {
306
- publicClient: PublicClient;
307
- walletClient: WalletClient;
308
- contractAddress: Hex;
309
- rootPublicKey?: NajPublicKey;
310
- }
311
- interface SignOptions {
312
- sign: {
313
- algo?: string;
314
- dest?: string;
315
- params?: string;
316
- };
317
- retry: {
318
- delay?: number;
319
- retryCount?: number;
320
- };
321
- }
322
- interface SignatureErrorData {
323
- requestId: string;
324
- responder: string;
325
- error: string;
326
- }
327
-
328
- declare class ChainSignatureContract extends ChainSignatureContract$2 {
329
- private readonly publicClient;
330
- private readonly walletClient;
331
- private readonly contractAddress;
332
- private readonly rootPublicKey;
333
- constructor(args: ChainSignatureContractArgs);
334
- getCurrentSignatureDeposit(): Promise<BN>;
335
- getDerivedPublicKey(args: {
336
- path: string;
337
- predecessor: string;
338
- }): Promise<UncompressedPubKeySEC1>;
339
- getPublicKey(): Promise<UncompressedPubKeySEC1>;
340
- getLatestKeyVersion(): Promise<number>;
341
- sign(args: SignArgs, options?: SignOptions): Promise<RSVSignature>;
342
- private getRequestId;
343
- getErrorFromEvents(requestId: `0x${string}`, receipt: TransactionReceipt): Promise<SignatureErrorData | undefined>;
344
- getSignatureFromEvents(requestId: `0x${string}`, receipt: TransactionReceipt): Promise<RSVSignature | undefined>;
345
- }
346
-
347
- type index$2_ChainSignatureContract = ChainSignatureContract;
348
- declare const index$2_ChainSignatureContract: typeof ChainSignatureContract;
349
- declare namespace index$2 {
350
- export { index$2_ChainSignatureContract as ChainSignatureContract };
351
- }
352
-
353
- declare namespace index$1 {
354
- export { index$2 as evm, index$3 as near };
355
- }
356
-
357
- declare const toRSV: (signature: MPCSignature) => RSVSignature;
358
- /**
359
- * Compresses an uncompressed public key to its compressed format following SEC1 standards.
360
- * In SEC1, a compressed public key consists of a prefix (02 or 03) followed by the x-coordinate.
361
- * The prefix indicates whether the y-coordinate is even (02) or odd (03).
362
- *
363
- * @param uncompressedPubKeySEC1 - The uncompressed public key in hex format, with or without '04' prefix
364
- * @returns The compressed public key in hex format
365
- * @throws Error if the uncompressed public key length is invalid
366
- */
367
- declare const compressPubKey: (uncompressedPubKeySEC1: UncompressedPubKeySEC1) => string;
368
- declare const najToUncompressedPubKeySEC1: (najPublicKey: NajPublicKey) => UncompressedPubKeySEC1;
369
- /**
370
- * Derives a child public key from a parent public key using the sig.network v1.0.0 epsilon derivation scheme.
371
- * The parent public keys are defined in @constants.ts as ROOT_PUBLIC_KEY_V1_SIG_NET_TESTNET and ROOT_PUBLIC_KEY_DEV_V1_SIG_NET_TESTNET.
372
- *
373
- * @param najPublicKey - The parent public key in NAJ format (e.g. secp256k1:3Ww8iFjqTHufye5aRGUvrQqETegR4gVUcW8FX5xzscaN9ENhpkffojsxJwi6N1RbbHMTxYa9UyKeqK3fsMuwxjR5)
374
- * @param predecessorId - The predecessor ID calling the signer contract
375
- * @param path - Optional derivation path suffix (defaults to empty string)
376
- * @returns The derived child public key in uncompressed SEC1 format (04 || x || y)
377
- */
378
- declare function deriveChildPublicKey(rootUncompressedPubKeySEC1: UncompressedPubKeySEC1, predecessorId: string, path: string | undefined, chainId: string): UncompressedPubKeySEC1;
379
-
380
- declare const cryptography_compressPubKey: typeof compressPubKey;
381
- declare const cryptography_deriveChildPublicKey: typeof deriveChildPublicKey;
382
- declare const cryptography_najToUncompressedPubKeySEC1: typeof najToUncompressedPubKeySEC1;
383
- declare const cryptography_toRSV: typeof toRSV;
384
- declare namespace cryptography {
385
- export { cryptography_compressPubKey as compressPubKey, cryptography_deriveChildPublicKey as deriveChildPublicKey, cryptography_najToUncompressedPubKeySEC1 as najToUncompressedPubKeySEC1, cryptography_toRSV as toRSV };
386
- }
387
-
388
- declare const index_cryptography: typeof cryptography;
389
- declare namespace index {
390
- export { index$1 as chains, index_cryptography as cryptography };
391
- }
392
-
393
- declare abstract class Chain<TransactionRequest, UnsignedTransaction> {
394
- /**
395
- * Gets the native token balance and decimals for a given address
396
- *
397
- * @param address - The address to check
398
- * @returns Promise resolving to an object containing:
399
- * - balance: The balance as a bigint, in the chain's base units
400
- * - decimals: The number of decimals used to format the balance
401
- */
402
- abstract getBalance(address: string): Promise<{
403
- balance: bigint;
404
- decimals: number;
405
- }>;
406
- /**
407
- * Uses Sig Network Key Derivation Function to derive the address and public key. from a signer ID and string path.
408
- *
409
- * @param predecessor - The id/address of the account requesting signature
410
- * @param path - The string path used to derive the key
411
- * @returns Promise resolving to the derived address and public key
412
- */
413
- abstract deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
414
- address: string;
415
- publicKey: string;
416
- }>;
417
- /**
418
- * Serializes an unsigned transaction to a string format.
419
- * This is useful for storing or transmitting the transaction.
420
- *
421
- * @param transaction - The unsigned transaction to serialize
422
- * @returns The serialized transaction string
423
- */
424
- abstract serializeTransaction(transaction: UnsignedTransaction): string;
425
- /**
426
- * Deserializes a transaction string back into an unsigned transaction object.
427
- * This reverses the serialization done by serializeTransaction().
428
- *
429
- * @param serialized - The serialized transaction string
430
- * @returns The deserialized unsigned transaction
431
- */
432
- abstract deserializeTransaction(serialized: string): UnsignedTransaction;
433
- /**
434
- * Prepares a transaction for Sig Network MPC signing by creating the necessary payloads.
435
- * This method handles chain-specific transaction preparation including:
436
- * - Fee calculation
437
- * - Nonce/sequence management
438
- * - UTXO selection (for UTXO-based chains)
439
- * - Transaction encoding
440
- *
441
- * @param transactionRequest - The transaction request containing parameters like recipient, amount, etc.
442
- * @returns Promise resolving to an object containing:
443
- * - transaction: The unsigned transaction
444
- * - mpcPayloads: Array of payloads to be signed by MPC. The order of these payloads must match
445
- * the order of signatures provided to attachTransactionSignature()
446
- */
447
- abstract prepareTransactionForSigning(transactionRequest: TransactionRequest): Promise<{
448
- transaction: UnsignedTransaction;
449
- mpcPayloads: MPCPayloads;
450
- }>;
451
- /**
452
- * Adds Sig Network MPC-generated signatures to an unsigned transaction.
453
- *
454
- * @param params - Parameters for adding signatures
455
- * @param params.transaction - The unsigned transaction to add signatures to
456
- * @param params.mpcSignatures - Array of RSV signatures generated through MPC. Must be in the same order
457
- * as the payloads returned by prepareTransactionForSigning()
458
- * @returns The serialized signed transaction ready for broadcast
459
- */
460
- abstract attachTransactionSignature(params: {
461
- transaction: UnsignedTransaction;
462
- mpcSignatures: RSVSignature[];
463
- }): string;
464
- /**
465
- * Broadcasts a signed transaction to the network.
466
- *
467
- * @param txSerialized - The serialized signed transaction
468
- * @returns Promise resolving to the transaction hash/ID
469
- */
470
- abstract broadcastTx(txSerialized: string): Promise<string>;
471
- }
472
-
473
- /**
474
- * Implementation of the Chain interface for EVM-compatible networks.
475
- * Handles interactions with Ethereum Virtual Machine based blockchains like Ethereum, BSC, Polygon, etc.
476
- */
477
- declare class EVM extends Chain<EVMTransactionRequest, EVMUnsignedTransaction> {
478
- private readonly client;
479
- private readonly contract;
480
- /**
481
- * Creates a new EVM chain instance
482
- * @param params - Configuration parameters
483
- * @param params.rpcUrl - URL of the EVM JSON-RPC provider (e.g., Infura endpoint)
484
- * @param params.contract - Instance of the chain signature contract for MPC operations
485
- */
486
- constructor({ rpcUrl, contract, }: {
487
- rpcUrl: string;
488
- contract: BaseChainSignatureContract;
489
- });
490
- private attachGasAndNonce;
491
- private parseSignature;
492
- deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
493
- address: string;
494
- publicKey: string;
495
- }>;
496
- getBalance(address: string): Promise<{
497
- balance: bigint;
498
- decimals: number;
499
- }>;
500
- serializeTransaction(transaction: EVMUnsignedTransaction): `0x${string}`;
501
- deserializeTransaction(serialized: `0x${string}`): EVMUnsignedTransaction;
502
- prepareTransactionForSigning(transactionRequest: EVMTransactionRequest): Promise<{
503
- transaction: EVMUnsignedTransaction;
504
- mpcPayloads: MPCPayloads;
505
- }>;
506
- prepareMessageForSigning(message: EVMMessage): Promise<{
507
- message: EVMMessage;
508
- mpcPayloads: MPCPayloads;
509
- }>;
510
- prepareTypedDataForSigning(typedDataRequest: EVMTypedData): Promise<{
511
- typedData: EVMTypedData;
512
- mpcPayloads: MPCPayloads;
513
- }>;
514
- /**
515
- * This implementation is a common step for Biconomy and Alchemy.
516
- * Key differences between implementations:
517
- * - Signature format: Biconomy omits 0x00 prefix when concatenating, Alchemy includes it
518
- * - Version support: Biconomy only supports v6, Alchemy supports both v6 and v7
519
- * - Validation: Biconomy uses modules for signature validation, Alchemy uses built-in validation
520
- */
521
- prepareUserOpForSigning(userOp: UserOperationV7 | UserOperationV6, entryPointAddress?: Address, chainIdArgs?: number): Promise<{
522
- userOp: UserOperationV7 | UserOperationV6;
523
- mpcPayloads: MPCPayloads;
524
- }>;
525
- attachTransactionSignature({ transaction, mpcSignatures, }: {
526
- transaction: EVMUnsignedTransaction;
527
- mpcSignatures: RSVSignature[];
528
- }): `0x02${string}`;
529
- attachMessageSignature({ mpcSignatures, }: {
530
- message: string;
531
- mpcSignatures: RSVSignature[];
532
- }): Hex;
533
- attachTypedDataSignature({ mpcSignatures, }: {
534
- typedData: EVMTypedData;
535
- mpcSignatures: RSVSignature[];
536
- }): Hex;
537
- attachUserOpSignature({ userOp, mpcSignatures, }: {
538
- userOp: UserOperationV7 | UserOperationV6;
539
- mpcSignatures: RSVSignature[];
540
- }): UserOperationV7 | UserOperationV6;
541
- broadcastTx(txSerialized: `0x${string}`): Promise<Hash>;
542
- }
543
-
544
- interface EVMFeeProperties {
545
- gas: bigint;
546
- maxFeePerGas: bigint;
547
- maxPriorityFeePerGas: bigint;
548
- }
549
- declare function fetchEVMFeeProperties(client: PublicClient, transaction: TransactionRequest): Promise<EVMFeeProperties>;
550
-
551
- declare abstract class BTCRpcAdapter {
552
- abstract selectUTXOs(from: string, targets: BTCOutput[]): Promise<{
553
- inputs: BTCInput[];
554
- outputs: BTCOutput[];
555
- }>;
556
- abstract broadcastTransaction(transactionHex: string): Promise<string>;
557
- abstract getBalance(address: string): Promise<number>;
558
- abstract getTransaction(txid: string): Promise<BTCTransaction$1>;
559
- }
560
-
561
- declare class Mempool extends BTCRpcAdapter {
562
- private readonly providerUrl;
563
- constructor(providerUrl: string);
564
- private fetchFeeRate;
565
- private fetchUTXOs;
566
- selectUTXOs(from: string, targets: BTCOutput[], confirmationTarget?: number): Promise<{
567
- inputs: BTCInput[];
568
- outputs: BTCOutput[];
569
- }>;
570
- broadcastTransaction(transactionHex: string): Promise<string>;
571
- getBalance(address: string): Promise<number>;
572
- getTransaction(txid: string): Promise<BTCTransaction$1>;
573
- }
574
-
575
- declare const BTCRpcAdapters: {
576
- Mempool: typeof Mempool;
577
- };
578
-
579
- /**
580
- * Implementation of the Chain interface for Bitcoin network.
581
- * Handles interactions with both Bitcoin mainnet and testnet, supporting P2WPKH transactions.
582
- */
583
- declare class Bitcoin extends Chain<BTCTransactionRequest, BTCUnsignedTransaction> {
584
- private static readonly SATOSHIS_PER_BTC;
585
- private readonly network;
586
- private readonly btcRpcAdapter;
587
- private readonly contract;
588
- /**
589
- * Creates a new Bitcoin chain instance
590
- * @param params - Configuration parameters
591
- * @param params.network - Network identifier (mainnet/testnet)
592
- * @param params.contract - Instance of the chain signature contract for MPC operations
593
- * @param params.btcRpcAdapter - Bitcoin RPC adapter for network interactions
594
- */
595
- constructor({ network, contract, btcRpcAdapter, }: {
596
- network: BTCNetworkIds;
597
- contract: BaseChainSignatureContract;
598
- btcRpcAdapter: BTCRpcAdapter;
599
- });
600
- /**
601
- * Converts satoshis to BTC
602
- * @param satoshis - Amount in satoshis
603
- * @returns Amount in BTC
604
- */
605
- static toBTC(satoshis: number): number;
606
- /**
607
- * Converts BTC to satoshis
608
- * @param btc - Amount in BTC
609
- * @returns Amount in satoshis (rounded)
610
- */
611
- static toSatoshi(btc: number): number;
612
- private fetchTransaction;
613
- private static parseRSVSignature;
614
- /**
615
- * Creates a Partially Signed Bitcoin Transaction (PSBT)
616
- * @param params - Parameters for creating the PSBT
617
- * @param params.transactionRequest - Transaction request containing inputs and outputs
618
- * @returns Created PSBT instance
619
- */
620
- createPSBT({ transactionRequest, }: {
621
- transactionRequest: BTCTransactionRequest;
622
- }): Promise<bitcoin.Psbt>;
623
- getBalance(address: string): Promise<{
624
- balance: bigint;
625
- decimals: number;
626
- }>;
627
- deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
628
- address: string;
629
- publicKey: string;
630
- }>;
631
- serializeTransaction(transaction: BTCUnsignedTransaction): string;
632
- deserializeTransaction(serialized: string): BTCUnsignedTransaction;
633
- prepareTransactionForSigning(transactionRequest: BTCTransactionRequest): Promise<{
634
- transaction: BTCUnsignedTransaction;
635
- mpcPayloads: MPCPayloads;
636
- }>;
637
- attachTransactionSignature({ transaction: { psbt, publicKey }, mpcSignatures, }: {
638
- transaction: BTCUnsignedTransaction;
639
- mpcSignatures: RSVSignature[];
640
- }): string;
641
- broadcastTx(txSerialized: string): Promise<string>;
642
- }
643
-
644
- /**
645
- * Implementation of the Chain interface for Cosmos-based networks.
646
- * Handles interactions with Cosmos SDK chains like Cosmos Hub, Osmosis, etc.
647
- */
648
- declare class Cosmos extends Chain<CosmosTransactionRequest, CosmosUnsignedTransaction> {
649
- private readonly registry;
650
- private readonly chainId;
651
- private readonly contract;
652
- private readonly endpoints?;
653
- /**
654
- * Creates a new Cosmos chain instance
655
- * @param params - Configuration parameters
656
- * @param params.chainId - Chain id for the Cosmos network
657
- * @param params.contract - Instance of the chain signature contract for MPC operations
658
- * @param params.endpoints - Optional RPC and REST endpoints
659
- * @param params.endpoints.rpcUrl - Optional RPC endpoint URL
660
- * @param params.endpoints.restUrl - Optional REST endpoint URL
661
- */
662
- constructor({ chainId, contract, endpoints, }: {
663
- contract: BaseChainSignatureContract;
664
- chainId: CosmosNetworkIds;
665
- endpoints?: {
666
- rpcUrl?: string;
667
- restUrl?: string;
668
- };
669
- });
670
- private parseRSVSignature;
671
- private getChainInfo;
672
- getBalance(address: string): Promise<{
673
- balance: bigint;
674
- decimals: number;
675
- }>;
676
- deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
677
- address: string;
678
- publicKey: string;
679
- }>;
680
- serializeTransaction(transaction: CosmosUnsignedTransaction): string;
681
- deserializeTransaction(serialized: string): CosmosUnsignedTransaction;
682
- prepareTransactionForSigning(transactionRequest: CosmosTransactionRequest): Promise<{
683
- transaction: CosmosUnsignedTransaction;
684
- mpcPayloads: MPCPayloads;
685
- }>;
686
- attachTransactionSignature({ transaction, mpcSignatures, }: {
687
- transaction: CosmosUnsignedTransaction;
688
- mpcSignatures: RSVSignature[];
689
- }): string;
690
- broadcastTx(txSerialized: string): Promise<string>;
691
- }
692
-
693
- 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 EVMTransactionRequest, type EVMUnsignedTransaction, type KeyDerivationPath, type MPCPayloads, type MPCSignature, type NajPublicKey, type RSVSignature, type SignArgs, type UncompressedPubKeySEC1, fetchEVMFeeProperties, index as utils };
package/node/index.d.ts DELETED
@@ -1,693 +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 MPCPayloads = Array<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 OldMpcSignature {
77
- big_r: {
78
- affine_point: string;
79
- };
80
- s: {
81
- scalar: string;
82
- };
83
- recovery_id: number;
84
- }
85
- interface NewMpcSignature {
86
- big_r: string;
87
- s: string;
88
- recovery_id: number;
89
- }
90
- type MPCSignature = OldMpcSignature | NewMpcSignature;
91
-
92
- interface BTCTransaction$1 {
93
- vout: Array<{
94
- scriptpubkey: string;
95
- value: number;
96
- }>;
97
- }
98
- interface BTCInput {
99
- txid: string;
100
- vout: number;
101
- value: number;
102
- scriptPubKey: Buffer;
103
- }
104
- type BTCOutput = {
105
- value: number;
106
- } | {
107
- address: string;
108
- value: number;
109
- } | {
110
- script: Buffer;
111
- value: number;
112
- };
113
- type BTCTransactionRequest = {
114
- publicKey: string;
115
- } & ({
116
- inputs: BTCInput[];
117
- outputs: BTCOutput[];
118
- from?: never;
119
- to?: never;
120
- value?: never;
121
- } | {
122
- inputs?: never;
123
- outputs?: never;
124
- from: string;
125
- to: string;
126
- value: string;
127
- });
128
- interface BTCUnsignedTransaction {
129
- psbt: bitcoin.Psbt;
130
- publicKey: string;
131
- }
132
- type BTCNetworkIds = 'mainnet' | 'testnet' | 'regtest';
133
-
134
- type CosmosNetworkIds = string;
135
- type CosmosUnsignedTransaction = TxRaw;
136
- interface CosmosTransactionRequest {
137
- address: string;
138
- publicKey: string;
139
- messages: EncodeObject[];
140
- memo?: string;
141
- gas?: number;
142
- }
143
-
144
- type EVMUnsignedTransaction = TransactionRequest & {
145
- type: 'eip1559';
146
- chainId: number;
147
- };
148
- interface EVMTransactionRequest extends Omit<EVMUnsignedTransaction, 'chainId' | 'type'> {
149
- from: Address;
150
- }
151
- type EVMMessage = SignableMessage;
152
- type EVMTypedData = TypedDataDefinition;
153
- interface UserOperationV7 {
154
- sender: Hex;
155
- nonce: Hex;
156
- factory: Hex;
157
- factoryData: Hex;
158
- callData: Hex;
159
- callGasLimit: Hex;
160
- verificationGasLimit: Hex;
161
- preVerificationGas: Hex;
162
- maxFeePerGas: Hex;
163
- maxPriorityFeePerGas: Hex;
164
- paymaster: Hex;
165
- paymasterVerificationGasLimit: Hex;
166
- paymasterPostOpGasLimit: Hex;
167
- paymasterData: Hex;
168
- signature: Hex;
169
- }
170
- interface UserOperationV6 {
171
- sender: Hex;
172
- nonce: Hex;
173
- initCode: Hex;
174
- callData: Hex;
175
- callGasLimit: Hex;
176
- verificationGasLimit: Hex;
177
- preVerificationGas: Hex;
178
- maxFeePerGas: Hex;
179
- maxPriorityFeePerGas: Hex;
180
- paymasterAndData: Hex;
181
- signature: Hex;
182
- }
183
-
184
- /**
185
- Available ChainSignature contracts:
186
- - Mainnet: v1.signer
187
- - Testnet: v1.signer-prod.testnet
188
- - Development (unstable): v1.signer-dev.testnet
189
- */
190
- type ChainSignatureContractIds = string;
191
- type NearNetworkIds = 'mainnet' | 'testnet';
192
- interface ChainProvider {
193
- providerUrl: string;
194
- contract: ChainSignatureContractIds;
195
- }
196
- interface NearAuthentication {
197
- networkId: NearNetworkIds;
198
- accountId: string;
199
- }
200
- interface SuccessResponse {
201
- transactionHash: string;
202
- success: true;
203
- }
204
- interface FailureResponse {
205
- success: false;
206
- errorMessage: string;
207
- }
208
- type Response = SuccessResponse | FailureResponse;
209
- type EVMChainConfigWithProviders = ChainProvider;
210
- interface EVMRequest {
211
- transaction: EVMTransactionRequest;
212
- chainConfig: EVMChainConfigWithProviders;
213
- nearAuthentication: NearAuthentication;
214
- fastAuthRelayerUrl?: string;
215
- derivationPath: KeyDerivationPath;
216
- }
217
- type BTCChainConfigWithProviders = ChainProvider & {
218
- network: BTCNetworkIds;
219
- };
220
- interface BitcoinRequest {
221
- transaction: BTCTransactionRequest;
222
- chainConfig: BTCChainConfigWithProviders;
223
- nearAuthentication: NearAuthentication;
224
- fastAuthRelayerUrl?: string;
225
- derivationPath: KeyDerivationPath;
226
- }
227
- interface CosmosChainConfig {
228
- contract: ChainSignatureContractIds;
229
- chainId: CosmosNetworkIds;
230
- }
231
- interface CosmosRequest {
232
- chainConfig: CosmosChainConfig;
233
- transaction: CosmosTransactionRequest;
234
- nearAuthentication: NearAuthentication;
235
- derivationPath: KeyDerivationPath;
236
- fastAuthRelayerUrl?: string;
237
- }
238
-
239
- declare const mpcPayloadsToChainSigTransaction: ({ networkId, contractId, mpcPayloads, path, }: {
240
- networkId: NetworkId;
241
- contractId: ChainSignatureContractIds;
242
- mpcPayloads: MPCPayloads;
243
- path: KeyDerivationPath;
244
- }) => Promise<{
245
- receiverId: string;
246
- actions: Action[];
247
- }>;
248
- declare const responseToMpcSignature: ({ response, }: {
249
- response: FinalExecutionOutcome;
250
- }) => RSVSignature | undefined;
251
-
252
- declare const transactionBuilder_mpcPayloadsToChainSigTransaction: typeof mpcPayloadsToChainSigTransaction;
253
- declare const transactionBuilder_responseToMpcSignature: typeof responseToMpcSignature;
254
- declare namespace transactionBuilder {
255
- export { transactionBuilder_mpcPayloadsToChainSigTransaction as mpcPayloadsToChainSigTransaction, transactionBuilder_responseToMpcSignature as responseToMpcSignature };
256
- }
257
-
258
- declare const EVMTransaction: (req: EVMRequest, keyPair: KeyPair) => Promise<Response>;
259
- declare const BTCTransaction: (req: BitcoinRequest, keyPair: KeyPair) => Promise<Response>;
260
- declare const CosmosTransaction: (req: CosmosRequest, keyPair: KeyPair) => Promise<Response>;
261
-
262
- declare const keypair_BTCTransaction: typeof BTCTransaction;
263
- declare const keypair_CosmosTransaction: typeof CosmosTransaction;
264
- declare const keypair_EVMTransaction: typeof EVMTransaction;
265
- declare namespace keypair {
266
- export { keypair_BTCTransaction as BTCTransaction, keypair_CosmosTransaction as CosmosTransaction, keypair_EVMTransaction as EVMTransaction };
267
- }
268
-
269
- declare const index$4_keypair: typeof keypair;
270
- declare namespace index$4 {
271
- export { index$4_keypair as keypair };
272
- }
273
-
274
- interface ChainSignatureContractArgs$1 {
275
- networkId: NearNetworkIds;
276
- contractId: ChainSignatureContractIds;
277
- accountId?: string;
278
- keypair?: KeyPair;
279
- }
280
- /**
281
- * This contract will default to view methods only.
282
- * If you want to use the change methods, you need to provide an account and keypair.
283
- */
284
- declare class ChainSignatureContract$1 extends ChainSignatureContract$2 {
285
- private readonly networkId;
286
- private readonly contractId;
287
- private readonly accountId;
288
- private readonly keypair;
289
- constructor({ networkId, contractId, accountId, keypair, }: ChainSignatureContractArgs$1);
290
- private getContract;
291
- getCurrentSignatureDeposit(): Promise<BN>;
292
- getDerivedPublicKey(args: {
293
- path: string;
294
- predecessor: string;
295
- }): Promise<UncompressedPubKeySEC1>;
296
- getPublicKey(): Promise<UncompressedPubKeySEC1>;
297
- sign(args: SignArgs): Promise<RSVSignature>;
298
- }
299
-
300
- declare const index$3_transactionBuilder: typeof transactionBuilder;
301
- declare namespace index$3 {
302
- export { ChainSignatureContract$1 as ChainSignatureContract, index$4 as signAndSend, index$3_transactionBuilder as transactionBuilder };
303
- }
304
-
305
- interface ChainSignatureContractArgs {
306
- publicClient: PublicClient;
307
- walletClient: WalletClient;
308
- contractAddress: Hex;
309
- rootPublicKey?: NajPublicKey;
310
- }
311
- interface SignOptions {
312
- sign: {
313
- algo?: string;
314
- dest?: string;
315
- params?: string;
316
- };
317
- retry: {
318
- delay?: number;
319
- retryCount?: number;
320
- };
321
- }
322
- interface SignatureErrorData {
323
- requestId: string;
324
- responder: string;
325
- error: string;
326
- }
327
-
328
- declare class ChainSignatureContract extends ChainSignatureContract$2 {
329
- private readonly publicClient;
330
- private readonly walletClient;
331
- private readonly contractAddress;
332
- private readonly rootPublicKey;
333
- constructor(args: ChainSignatureContractArgs);
334
- getCurrentSignatureDeposit(): Promise<BN>;
335
- getDerivedPublicKey(args: {
336
- path: string;
337
- predecessor: string;
338
- }): Promise<UncompressedPubKeySEC1>;
339
- getPublicKey(): Promise<UncompressedPubKeySEC1>;
340
- getLatestKeyVersion(): Promise<number>;
341
- sign(args: SignArgs, options?: SignOptions): Promise<RSVSignature>;
342
- private getRequestId;
343
- getErrorFromEvents(requestId: `0x${string}`, receipt: TransactionReceipt): Promise<SignatureErrorData | undefined>;
344
- getSignatureFromEvents(requestId: `0x${string}`, receipt: TransactionReceipt): Promise<RSVSignature | undefined>;
345
- }
346
-
347
- type index$2_ChainSignatureContract = ChainSignatureContract;
348
- declare const index$2_ChainSignatureContract: typeof ChainSignatureContract;
349
- declare namespace index$2 {
350
- export { index$2_ChainSignatureContract as ChainSignatureContract };
351
- }
352
-
353
- declare namespace index$1 {
354
- export { index$2 as evm, index$3 as near };
355
- }
356
-
357
- declare const toRSV: (signature: MPCSignature) => RSVSignature;
358
- /**
359
- * Compresses an uncompressed public key to its compressed format following SEC1 standards.
360
- * In SEC1, a compressed public key consists of a prefix (02 or 03) followed by the x-coordinate.
361
- * The prefix indicates whether the y-coordinate is even (02) or odd (03).
362
- *
363
- * @param uncompressedPubKeySEC1 - The uncompressed public key in hex format, with or without '04' prefix
364
- * @returns The compressed public key in hex format
365
- * @throws Error if the uncompressed public key length is invalid
366
- */
367
- declare const compressPubKey: (uncompressedPubKeySEC1: UncompressedPubKeySEC1) => string;
368
- declare const najToUncompressedPubKeySEC1: (najPublicKey: NajPublicKey) => UncompressedPubKeySEC1;
369
- /**
370
- * Derives a child public key from a parent public key using the sig.network v1.0.0 epsilon derivation scheme.
371
- * The parent public keys are defined in @constants.ts as ROOT_PUBLIC_KEY_V1_SIG_NET_TESTNET and ROOT_PUBLIC_KEY_DEV_V1_SIG_NET_TESTNET.
372
- *
373
- * @param najPublicKey - The parent public key in NAJ format (e.g. secp256k1:3Ww8iFjqTHufye5aRGUvrQqETegR4gVUcW8FX5xzscaN9ENhpkffojsxJwi6N1RbbHMTxYa9UyKeqK3fsMuwxjR5)
374
- * @param predecessorId - The predecessor ID calling the signer contract
375
- * @param path - Optional derivation path suffix (defaults to empty string)
376
- * @returns The derived child public key in uncompressed SEC1 format (04 || x || y)
377
- */
378
- declare function deriveChildPublicKey(rootUncompressedPubKeySEC1: UncompressedPubKeySEC1, predecessorId: string, path: string | undefined, chainId: string): UncompressedPubKeySEC1;
379
-
380
- declare const cryptography_compressPubKey: typeof compressPubKey;
381
- declare const cryptography_deriveChildPublicKey: typeof deriveChildPublicKey;
382
- declare const cryptography_najToUncompressedPubKeySEC1: typeof najToUncompressedPubKeySEC1;
383
- declare const cryptography_toRSV: typeof toRSV;
384
- declare namespace cryptography {
385
- export { cryptography_compressPubKey as compressPubKey, cryptography_deriveChildPublicKey as deriveChildPublicKey, cryptography_najToUncompressedPubKeySEC1 as najToUncompressedPubKeySEC1, cryptography_toRSV as toRSV };
386
- }
387
-
388
- declare const index_cryptography: typeof cryptography;
389
- declare namespace index {
390
- export { index$1 as chains, index_cryptography as cryptography };
391
- }
392
-
393
- declare abstract class Chain<TransactionRequest, UnsignedTransaction> {
394
- /**
395
- * Gets the native token balance and decimals for a given address
396
- *
397
- * @param address - The address to check
398
- * @returns Promise resolving to an object containing:
399
- * - balance: The balance as a bigint, in the chain's base units
400
- * - decimals: The number of decimals used to format the balance
401
- */
402
- abstract getBalance(address: string): Promise<{
403
- balance: bigint;
404
- decimals: number;
405
- }>;
406
- /**
407
- * Uses Sig Network Key Derivation Function to derive the address and public key. from a signer ID and string path.
408
- *
409
- * @param predecessor - The id/address of the account requesting signature
410
- * @param path - The string path used to derive the key
411
- * @returns Promise resolving to the derived address and public key
412
- */
413
- abstract deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
414
- address: string;
415
- publicKey: string;
416
- }>;
417
- /**
418
- * Serializes an unsigned transaction to a string format.
419
- * This is useful for storing or transmitting the transaction.
420
- *
421
- * @param transaction - The unsigned transaction to serialize
422
- * @returns The serialized transaction string
423
- */
424
- abstract serializeTransaction(transaction: UnsignedTransaction): string;
425
- /**
426
- * Deserializes a transaction string back into an unsigned transaction object.
427
- * This reverses the serialization done by serializeTransaction().
428
- *
429
- * @param serialized - The serialized transaction string
430
- * @returns The deserialized unsigned transaction
431
- */
432
- abstract deserializeTransaction(serialized: string): UnsignedTransaction;
433
- /**
434
- * Prepares a transaction for Sig Network MPC signing by creating the necessary payloads.
435
- * This method handles chain-specific transaction preparation including:
436
- * - Fee calculation
437
- * - Nonce/sequence management
438
- * - UTXO selection (for UTXO-based chains)
439
- * - Transaction encoding
440
- *
441
- * @param transactionRequest - The transaction request containing parameters like recipient, amount, etc.
442
- * @returns Promise resolving to an object containing:
443
- * - transaction: The unsigned transaction
444
- * - mpcPayloads: Array of payloads to be signed by MPC. The order of these payloads must match
445
- * the order of signatures provided to attachTransactionSignature()
446
- */
447
- abstract prepareTransactionForSigning(transactionRequest: TransactionRequest): Promise<{
448
- transaction: UnsignedTransaction;
449
- mpcPayloads: MPCPayloads;
450
- }>;
451
- /**
452
- * Adds Sig Network MPC-generated signatures to an unsigned transaction.
453
- *
454
- * @param params - Parameters for adding signatures
455
- * @param params.transaction - The unsigned transaction to add signatures to
456
- * @param params.mpcSignatures - Array of RSV signatures generated through MPC. Must be in the same order
457
- * as the payloads returned by prepareTransactionForSigning()
458
- * @returns The serialized signed transaction ready for broadcast
459
- */
460
- abstract attachTransactionSignature(params: {
461
- transaction: UnsignedTransaction;
462
- mpcSignatures: RSVSignature[];
463
- }): string;
464
- /**
465
- * Broadcasts a signed transaction to the network.
466
- *
467
- * @param txSerialized - The serialized signed transaction
468
- * @returns Promise resolving to the transaction hash/ID
469
- */
470
- abstract broadcastTx(txSerialized: string): Promise<string>;
471
- }
472
-
473
- /**
474
- * Implementation of the Chain interface for EVM-compatible networks.
475
- * Handles interactions with Ethereum Virtual Machine based blockchains like Ethereum, BSC, Polygon, etc.
476
- */
477
- declare class EVM extends Chain<EVMTransactionRequest, EVMUnsignedTransaction> {
478
- private readonly client;
479
- private readonly contract;
480
- /**
481
- * Creates a new EVM chain instance
482
- * @param params - Configuration parameters
483
- * @param params.rpcUrl - URL of the EVM JSON-RPC provider (e.g., Infura endpoint)
484
- * @param params.contract - Instance of the chain signature contract for MPC operations
485
- */
486
- constructor({ rpcUrl, contract, }: {
487
- rpcUrl: string;
488
- contract: BaseChainSignatureContract;
489
- });
490
- private attachGasAndNonce;
491
- private parseSignature;
492
- deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
493
- address: string;
494
- publicKey: string;
495
- }>;
496
- getBalance(address: string): Promise<{
497
- balance: bigint;
498
- decimals: number;
499
- }>;
500
- serializeTransaction(transaction: EVMUnsignedTransaction): `0x${string}`;
501
- deserializeTransaction(serialized: `0x${string}`): EVMUnsignedTransaction;
502
- prepareTransactionForSigning(transactionRequest: EVMTransactionRequest): Promise<{
503
- transaction: EVMUnsignedTransaction;
504
- mpcPayloads: MPCPayloads;
505
- }>;
506
- prepareMessageForSigning(message: EVMMessage): Promise<{
507
- message: EVMMessage;
508
- mpcPayloads: MPCPayloads;
509
- }>;
510
- prepareTypedDataForSigning(typedDataRequest: EVMTypedData): Promise<{
511
- typedData: EVMTypedData;
512
- mpcPayloads: MPCPayloads;
513
- }>;
514
- /**
515
- * This implementation is a common step for Biconomy and Alchemy.
516
- * Key differences between implementations:
517
- * - Signature format: Biconomy omits 0x00 prefix when concatenating, Alchemy includes it
518
- * - Version support: Biconomy only supports v6, Alchemy supports both v6 and v7
519
- * - Validation: Biconomy uses modules for signature validation, Alchemy uses built-in validation
520
- */
521
- prepareUserOpForSigning(userOp: UserOperationV7 | UserOperationV6, entryPointAddress?: Address, chainIdArgs?: number): Promise<{
522
- userOp: UserOperationV7 | UserOperationV6;
523
- mpcPayloads: MPCPayloads;
524
- }>;
525
- attachTransactionSignature({ transaction, mpcSignatures, }: {
526
- transaction: EVMUnsignedTransaction;
527
- mpcSignatures: RSVSignature[];
528
- }): `0x02${string}`;
529
- attachMessageSignature({ mpcSignatures, }: {
530
- message: string;
531
- mpcSignatures: RSVSignature[];
532
- }): Hex;
533
- attachTypedDataSignature({ mpcSignatures, }: {
534
- typedData: EVMTypedData;
535
- mpcSignatures: RSVSignature[];
536
- }): Hex;
537
- attachUserOpSignature({ userOp, mpcSignatures, }: {
538
- userOp: UserOperationV7 | UserOperationV6;
539
- mpcSignatures: RSVSignature[];
540
- }): UserOperationV7 | UserOperationV6;
541
- broadcastTx(txSerialized: `0x${string}`): Promise<Hash>;
542
- }
543
-
544
- interface EVMFeeProperties {
545
- gas: bigint;
546
- maxFeePerGas: bigint;
547
- maxPriorityFeePerGas: bigint;
548
- }
549
- declare function fetchEVMFeeProperties(client: PublicClient, transaction: TransactionRequest): Promise<EVMFeeProperties>;
550
-
551
- declare abstract class BTCRpcAdapter {
552
- abstract selectUTXOs(from: string, targets: BTCOutput[]): Promise<{
553
- inputs: BTCInput[];
554
- outputs: BTCOutput[];
555
- }>;
556
- abstract broadcastTransaction(transactionHex: string): Promise<string>;
557
- abstract getBalance(address: string): Promise<number>;
558
- abstract getTransaction(txid: string): Promise<BTCTransaction$1>;
559
- }
560
-
561
- declare class Mempool extends BTCRpcAdapter {
562
- private readonly providerUrl;
563
- constructor(providerUrl: string);
564
- private fetchFeeRate;
565
- private fetchUTXOs;
566
- selectUTXOs(from: string, targets: BTCOutput[], confirmationTarget?: number): Promise<{
567
- inputs: BTCInput[];
568
- outputs: BTCOutput[];
569
- }>;
570
- broadcastTransaction(transactionHex: string): Promise<string>;
571
- getBalance(address: string): Promise<number>;
572
- getTransaction(txid: string): Promise<BTCTransaction$1>;
573
- }
574
-
575
- declare const BTCRpcAdapters: {
576
- Mempool: typeof Mempool;
577
- };
578
-
579
- /**
580
- * Implementation of the Chain interface for Bitcoin network.
581
- * Handles interactions with both Bitcoin mainnet and testnet, supporting P2WPKH transactions.
582
- */
583
- declare class Bitcoin extends Chain<BTCTransactionRequest, BTCUnsignedTransaction> {
584
- private static readonly SATOSHIS_PER_BTC;
585
- private readonly network;
586
- private readonly btcRpcAdapter;
587
- private readonly contract;
588
- /**
589
- * Creates a new Bitcoin chain instance
590
- * @param params - Configuration parameters
591
- * @param params.network - Network identifier (mainnet/testnet)
592
- * @param params.contract - Instance of the chain signature contract for MPC operations
593
- * @param params.btcRpcAdapter - Bitcoin RPC adapter for network interactions
594
- */
595
- constructor({ network, contract, btcRpcAdapter, }: {
596
- network: BTCNetworkIds;
597
- contract: BaseChainSignatureContract;
598
- btcRpcAdapter: BTCRpcAdapter;
599
- });
600
- /**
601
- * Converts satoshis to BTC
602
- * @param satoshis - Amount in satoshis
603
- * @returns Amount in BTC
604
- */
605
- static toBTC(satoshis: number): number;
606
- /**
607
- * Converts BTC to satoshis
608
- * @param btc - Amount in BTC
609
- * @returns Amount in satoshis (rounded)
610
- */
611
- static toSatoshi(btc: number): number;
612
- private fetchTransaction;
613
- private static parseRSVSignature;
614
- /**
615
- * Creates a Partially Signed Bitcoin Transaction (PSBT)
616
- * @param params - Parameters for creating the PSBT
617
- * @param params.transactionRequest - Transaction request containing inputs and outputs
618
- * @returns Created PSBT instance
619
- */
620
- createPSBT({ transactionRequest, }: {
621
- transactionRequest: BTCTransactionRequest;
622
- }): Promise<bitcoin.Psbt>;
623
- getBalance(address: string): Promise<{
624
- balance: bigint;
625
- decimals: number;
626
- }>;
627
- deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
628
- address: string;
629
- publicKey: string;
630
- }>;
631
- serializeTransaction(transaction: BTCUnsignedTransaction): string;
632
- deserializeTransaction(serialized: string): BTCUnsignedTransaction;
633
- prepareTransactionForSigning(transactionRequest: BTCTransactionRequest): Promise<{
634
- transaction: BTCUnsignedTransaction;
635
- mpcPayloads: MPCPayloads;
636
- }>;
637
- attachTransactionSignature({ transaction: { psbt, publicKey }, mpcSignatures, }: {
638
- transaction: BTCUnsignedTransaction;
639
- mpcSignatures: RSVSignature[];
640
- }): string;
641
- broadcastTx(txSerialized: string): Promise<string>;
642
- }
643
-
644
- /**
645
- * Implementation of the Chain interface for Cosmos-based networks.
646
- * Handles interactions with Cosmos SDK chains like Cosmos Hub, Osmosis, etc.
647
- */
648
- declare class Cosmos extends Chain<CosmosTransactionRequest, CosmosUnsignedTransaction> {
649
- private readonly registry;
650
- private readonly chainId;
651
- private readonly contract;
652
- private readonly endpoints?;
653
- /**
654
- * Creates a new Cosmos chain instance
655
- * @param params - Configuration parameters
656
- * @param params.chainId - Chain id for the Cosmos network
657
- * @param params.contract - Instance of the chain signature contract for MPC operations
658
- * @param params.endpoints - Optional RPC and REST endpoints
659
- * @param params.endpoints.rpcUrl - Optional RPC endpoint URL
660
- * @param params.endpoints.restUrl - Optional REST endpoint URL
661
- */
662
- constructor({ chainId, contract, endpoints, }: {
663
- contract: BaseChainSignatureContract;
664
- chainId: CosmosNetworkIds;
665
- endpoints?: {
666
- rpcUrl?: string;
667
- restUrl?: string;
668
- };
669
- });
670
- private parseRSVSignature;
671
- private getChainInfo;
672
- getBalance(address: string): Promise<{
673
- balance: bigint;
674
- decimals: number;
675
- }>;
676
- deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
677
- address: string;
678
- publicKey: string;
679
- }>;
680
- serializeTransaction(transaction: CosmosUnsignedTransaction): string;
681
- deserializeTransaction(serialized: string): CosmosUnsignedTransaction;
682
- prepareTransactionForSigning(transactionRequest: CosmosTransactionRequest): Promise<{
683
- transaction: CosmosUnsignedTransaction;
684
- mpcPayloads: MPCPayloads;
685
- }>;
686
- attachTransactionSignature({ transaction, mpcSignatures, }: {
687
- transaction: CosmosUnsignedTransaction;
688
- mpcSignatures: RSVSignature[];
689
- }): string;
690
- broadcastTx(txSerialized: string): Promise<string>;
691
- }
692
-
693
- 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 EVMTransactionRequest, type EVMUnsignedTransaction, type KeyDerivationPath, type MPCPayloads, type MPCSignature, type NajPublicKey, type RSVSignature, type SignArgs, type UncompressedPubKeySEC1, fetchEVMFeeProperties, index as utils };