signet.js 0.0.1-beta.6 → 0.0.1-beta.8

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 (76) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +42 -14
  3. package/{src/chains → chains}/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.d.ts +1 -1
  4. package/{src/chains → chains}/Bitcoin/BTCRpcAdapter/Mempool/Mempool.d.ts +2 -2
  5. package/{src/chains → chains}/Bitcoin/Bitcoin.d.ts +5 -5
  6. package/{src/chains → chains}/Chain.d.ts +10 -25
  7. package/chains/ChainSignatureContract.d.ts +41 -0
  8. package/{src/chains → chains}/Cosmos/Cosmos.d.ts +3 -3
  9. package/{src/chains → chains}/Cosmos/types.d.ts +2 -2
  10. package/{src/chains → chains}/Cosmos/utils.d.ts +1 -1
  11. package/{src/chains → chains}/EVM/EVM.d.ts +3 -3
  12. package/{src/chains → chains}/types.d.ts +1 -1
  13. package/{src/chains → chains}/utils.d.ts +1 -1
  14. package/index.cjs +2 -0
  15. package/index.cjs.map +1 -0
  16. package/index.js +2674 -0
  17. package/index.js.map +1 -0
  18. package/package.json +20 -10
  19. package/{src/utils/chains/near/contract.d.ts → utils/chains/near/ChainSignatureContract.d.ts} +6 -8
  20. package/{src/utils → utils}/chains/near/constants.d.ts +1 -1
  21. package/{src/utils → utils}/chains/near/index.d.ts +1 -1
  22. package/{src/utils → utils}/chains/near/relayer/relayer.d.ts +2 -2
  23. package/{src/utils → utils}/chains/near/signAndSend/keypair.d.ts +3 -3
  24. package/{src/utils → utils}/chains/near/transactionBuilder.d.ts +3 -3
  25. package/{src/utils → utils}/chains/near/types.d.ts +4 -4
  26. package/src/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.js +0 -2
  27. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.js +0 -69
  28. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/index.js +0 -1
  29. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/types.js +0 -1
  30. package/src/chains/Bitcoin/BTCRpcAdapter/index.js +0 -5
  31. package/src/chains/Bitcoin/Bitcoin.js +0 -198
  32. package/src/chains/Bitcoin/types.js +0 -1
  33. package/src/chains/Bitcoin/utils.js +0 -13
  34. package/src/chains/Chain.js +0 -9
  35. package/src/chains/ChainSignatureContract.d.ts +0 -62
  36. package/src/chains/ChainSignatureContract.js +0 -7
  37. package/src/chains/Cosmos/Cosmos.js +0 -157
  38. package/src/chains/Cosmos/types.js +0 -1
  39. package/src/chains/Cosmos/utils.js +0 -27
  40. package/src/chains/EVM/EVM.js +0 -109
  41. package/src/chains/EVM/types.js +0 -1
  42. package/src/chains/EVM/utils.js +0 -14
  43. package/src/chains/index.js +0 -12
  44. package/src/chains/types.js +0 -1
  45. package/src/chains/utils.js +0 -27
  46. package/src/index.js +0 -2
  47. package/src/utils/chains/index.js +0 -1
  48. package/src/utils/chains/near/account.js +0 -22
  49. package/src/utils/chains/near/constants.js +0 -3
  50. package/src/utils/chains/near/contract.js +0 -102
  51. package/src/utils/chains/near/index.js +0 -3
  52. package/src/utils/chains/near/relayer/index.js +0 -1
  53. package/src/utils/chains/near/relayer/relayer.js +0 -33
  54. package/src/utils/chains/near/relayer/types.js +0 -1
  55. package/src/utils/chains/near/signAndSend/index.js +0 -1
  56. package/src/utils/chains/near/signAndSend/keypair.js +0 -127
  57. package/src/utils/chains/near/transactionBuilder.js +0 -72
  58. package/src/utils/chains/near/types.js +0 -1
  59. package/src/utils/index.js +0 -1
  60. package/vocs.config.d.ts +0 -3
  61. package/vocs.config.js +0 -71
  62. /package/{src/chains → chains}/Bitcoin/BTCRpcAdapter/Mempool/index.d.ts +0 -0
  63. /package/{src/chains → chains}/Bitcoin/BTCRpcAdapter/Mempool/types.d.ts +0 -0
  64. /package/{src/chains → chains}/Bitcoin/BTCRpcAdapter/index.d.ts +0 -0
  65. /package/{src/chains → chains}/Bitcoin/types.d.ts +0 -0
  66. /package/{src/chains → chains}/Bitcoin/utils.d.ts +0 -0
  67. /package/{src/chains → chains}/EVM/types.d.ts +0 -0
  68. /package/{src/chains → chains}/EVM/utils.d.ts +0 -0
  69. /package/{src/chains → chains}/index.d.ts +0 -0
  70. /package/{src/index.d.ts → index.d.ts} +0 -0
  71. /package/{src/utils → utils}/chains/index.d.ts +0 -0
  72. /package/{src/utils → utils}/chains/near/account.d.ts +0 -0
  73. /package/{src/utils → utils}/chains/near/relayer/index.d.ts +0 -0
  74. /package/{src/utils → utils}/chains/near/relayer/types.d.ts +0 -0
  75. /package/{src/utils → utils}/chains/near/signAndSend/index.d.ts +0 -0
  76. /package/{src/utils → utils}/index.d.ts +0 -0
package/package.json CHANGED
@@ -1,14 +1,27 @@
1
1
  {
2
2
  "name": "signet.js",
3
- "version": "0.0.1-beta.6",
3
+ "version": "0.0.1-beta.8",
4
4
  "description": "",
5
5
  "type": "module",
6
- "main": "./src/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./src/index.d.ts",
9
+ "import": {
10
+ "browser": "./index.js",
11
+ "node": "./index.js"
12
+ },
13
+ "require": "./index.cjs"
14
+ }
15
+ },
16
+ "main": "./index.cjs",
17
+ "module": "./index.js",
18
+ "browser": "./index.js",
7
19
  "types": "./src/index.d.ts",
8
20
  "scripts": {
9
- "build": "tsc --project tsconfig.json && tsc-alias",
10
- "pre:deploy": "npm run build && cp package.json README.md dist/",
11
- "publish-npm": "npm run pre:deploy && cd dist && npm publish",
21
+ "build": "rm -rf dist && vite build && cp package.json README.md LICENSE dist/",
22
+ "watch": "vite build --watch",
23
+ "pre:deploy": "npm run build && npm run docs:build",
24
+ "publish-npm": "npm run pre:deploy && npm publish",
12
25
  "publish-npm:beta": "npm run pre:deploy && cd dist && npm publish --tag beta",
13
26
  "test": "jest",
14
27
  "docs:dev": "vocs dev",
@@ -18,9 +31,6 @@
18
31
  "author": "",
19
32
  "license": "ISC",
20
33
  "devDependencies": {
21
- "@babel/core": "^7.25.2",
22
- "@babel/preset-env": "^7.25.3",
23
- "@babel/preset-typescript": "^7.24.7",
24
34
  "@types/bn.js": "^5.1.5",
25
35
  "@typescript-eslint/eslint-plugin": "^6.21.0",
26
36
  "babel-jest": "^29.7.0",
@@ -34,9 +44,9 @@
34
44
  "eslint-plugin-promise": "^6.1.1",
35
45
  "jest": "^29.7.0",
36
46
  "prettier": "^3.2.5",
37
- "ts-node": "^10.9.2",
38
- "tsc-alias": "^1.8.10",
39
47
  "typescript": "^5.4.3",
48
+ "vite": "^6.0.7",
49
+ "vite-plugin-dts": "^4.4.0",
40
50
  "vocs": "1.0.0-alpha.62"
41
51
  },
42
52
  "dependencies": {
@@ -1,10 +1,9 @@
1
- import { type Account } from '@near-js/accounts';
1
+ import { Account } from '@near-js/accounts';
2
2
  import { KeyPair } from '@near-js/crypto';
3
- import BN from 'bn.js';
4
- import { ChainSignatureContract } from '../../../chains/ChainSignatureContract';
5
- import type { RSVSignature, UncompressedPubKeySEC1 } from '../../../chains/types';
6
- import type { SignArgs } from '../../../chains/ChainSignatureContract';
7
- import { type NearNetworkIds, type ChainSignatureContractIds } from '../../chains/near/types';
3
+ import { default as BN } from 'bn.js';
4
+ import { ChainSignatureContract as AbstractChainSignatureContract, SignArgs } from '../../../chains/ChainSignatureContract';
5
+ import { RSVSignature, UncompressedPubKeySEC1 } from '../../../chains/types';
6
+ import { NearNetworkIds, ChainSignatureContractIds } from './types';
8
7
  interface ChainSignatureContractArgs {
9
8
  networkId: NearNetworkIds;
10
9
  contractId: ChainSignatureContractIds;
@@ -15,14 +14,13 @@ interface ChainSignatureContractArgs {
15
14
  * This contract will default to view methods only.
16
15
  * If you want to use the change methods, you need to provide an account and keypair.
17
16
  */
18
- export declare class NearChainSignatureContract extends ChainSignatureContract {
17
+ export declare class ChainSignatureContract extends AbstractChainSignatureContract {
19
18
  private readonly networkId;
20
19
  private readonly contractId;
21
20
  private readonly accountId;
22
21
  private readonly keypair;
23
22
  constructor({ networkId, contractId, accountId, keypair, }: ChainSignatureContractArgs);
24
23
  private getContract;
25
- getPublicKey(): Promise<UncompressedPubKeySEC1>;
26
24
  getCurrentSignatureDeposit(): Promise<BN>;
27
25
  getDerivedPublicKey(args: {
28
26
  path: string;
@@ -1,3 +1,3 @@
1
- import BN from 'bn.js';
1
+ import { default as BN } from 'bn.js';
2
2
  export declare const NEAR_MAX_GAS: BN;
3
3
  export declare const DONT_CARE_ACCOUNT_ID = "dontcare";
@@ -1,3 +1,3 @@
1
1
  export * as transactionBuilder from './transactionBuilder';
2
2
  export * as signAndSend from './signAndSend';
3
- export * as contract from './contract';
3
+ export * from './ChainSignatureContract';
@@ -1,5 +1,5 @@
1
- import { type SignedDelegate } from '@near-js/transactions';
2
- import { type SignedDelegateRelayerFormat } from './types';
1
+ import { SignedDelegate } from '@near-js/transactions';
2
+ import { SignedDelegateRelayerFormat } from './types';
3
3
  /**
4
4
  * Parses the signedDelegate object from the Multi-Party Computation (MPC) format to the Relayer format.
5
5
  * @param signedDelegate - The signedDelegate object in MPC format.
@@ -1,6 +1,6 @@
1
- import { type KeyPair } from '@near-js/crypto';
2
- import { type Response } from '../../../../chains/types';
3
- import { type BitcoinRequest, type CosmosRequest, type EVMRequest } from '../../../chains/near/types';
1
+ import { KeyPair } from '@near-js/crypto';
2
+ import { Response } from '../../../../chains/types';
3
+ import { BitcoinRequest, CosmosRequest, EVMRequest } from '../types';
4
4
  export declare const EVMTransaction: (req: EVMRequest, keyPair: KeyPair) => Promise<Response>;
5
5
  export declare const BTCTransaction: (req: BitcoinRequest, keyPair: KeyPair) => Promise<Response>;
6
6
  export declare const CosmosTransaction: (req: CosmosRequest, keyPair: KeyPair) => Promise<Response>;
@@ -1,6 +1,6 @@
1
- import type { Action, FinalExecutionOutcome, NetworkId } from '@near-wallet-selector/core';
2
- import { type RSVSignature, type KeyDerivationPath, type MPCPayloads } from '../../../chains/types';
3
- import { type NFTKeysContracts, type ChainSignatureContractIds } from '../../chains/near/types';
1
+ import { Action, FinalExecutionOutcome, NetworkId } from '@near-wallet-selector/core';
2
+ import { RSVSignature, KeyDerivationPath, MPCPayloads } from '../../../chains/types';
3
+ import { NFTKeysContracts, ChainSignatureContractIds } from './types';
4
4
  export declare const mpcPayloadsToChainSigTransaction: ({ networkId, contractId, mpcPayloads, path, }: {
5
5
  networkId: NetworkId;
6
6
  contractId: ChainSignatureContractIds;
@@ -1,7 +1,7 @@
1
- import type { KeyDerivationPath } from '../../../chains/types';
2
- import type { BTCTransactionRequest, BTCNetworkIds } from '../../../chains/Bitcoin/types';
3
- import type { CosmosNetworkIds, CosmosTransactionRequest } from '../../../chains/Cosmos/types';
4
- import { type EVMTransactionRequest } from '../../../chains/EVM/types';
1
+ import { BTCTransactionRequest, BTCNetworkIds } from '../../../chains/Bitcoin/types';
2
+ import { CosmosNetworkIds, CosmosTransactionRequest } from '../../../chains/Cosmos/types';
3
+ import { EVMTransactionRequest } from '../../../chains/EVM/types';
4
+ import { KeyDerivationPath } from '../../../chains/types';
5
5
  /**
6
6
  Available ChainSignature contracts:
7
7
  - Mainnet: v1.signer
@@ -1,2 +0,0 @@
1
- export class BTCRpcAdapter {
2
- }
@@ -1,69 +0,0 @@
1
- // There is no types for coinselect
2
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
- // @ts-expect-error
4
- import coinselect from 'coinselect';
5
- import { BTCRpcAdapter } from '../../../Bitcoin/BTCRpcAdapter/BTCRpcAdapter';
6
- export class Mempool extends BTCRpcAdapter {
7
- constructor(providerUrl) {
8
- super();
9
- this.providerUrl = providerUrl;
10
- }
11
- async fetchFeeRate(confirmationTarget = 6) {
12
- const response = await fetch(`${this.providerUrl}/v1/fees/recommended`);
13
- const data = (await response.json());
14
- if (confirmationTarget <= 1) {
15
- return data.fastestFee;
16
- }
17
- else if (confirmationTarget <= 3) {
18
- return data.halfHourFee;
19
- }
20
- else if (confirmationTarget <= 6) {
21
- return data.hourFee;
22
- }
23
- else {
24
- return data.economyFee;
25
- }
26
- }
27
- async fetchUTXOs(address) {
28
- try {
29
- const response = await fetch(`${this.providerUrl}/address/${address}/utxo`);
30
- return (await response.json());
31
- }
32
- catch (error) {
33
- console.error('Failed to fetch UTXOs:', error);
34
- return [];
35
- }
36
- }
37
- async selectUTXOs(from, targets, confirmationTarget = 6) {
38
- const utxos = await this.fetchUTXOs(from);
39
- const feeRate = await this.fetchFeeRate(confirmationTarget);
40
- // Add a small amount to the fee rate to ensure the transaction is confirmed
41
- const ret = coinselect(utxos, targets, Math.ceil(feeRate + 1));
42
- if (!ret.inputs || !ret.outputs) {
43
- throw new Error('Invalid transaction: coinselect failed to find a suitable set of inputs and outputs. This could be due to insufficient funds, or no inputs being available that meet the criteria.');
44
- }
45
- return {
46
- inputs: ret.inputs,
47
- outputs: ret.outputs,
48
- };
49
- }
50
- async broadcastTransaction(transactionHex) {
51
- const response = await fetch(`${this.providerUrl}/tx`, {
52
- method: 'POST',
53
- body: transactionHex,
54
- });
55
- if (response.ok) {
56
- return await response.text();
57
- }
58
- throw new Error(`Failed to broadcast transaction: ${await response.text()}`);
59
- }
60
- async getBalance(address) {
61
- const response = await fetch(`${this.providerUrl}/address/${address}`);
62
- const data = (await response.json());
63
- return data.chain_stats.funded_txo_sum - data.chain_stats.spent_txo_sum;
64
- }
65
- async getTransaction(txid) {
66
- const response = await fetch(`${this.providerUrl}/tx/${txid}`);
67
- return (await response.json());
68
- }
69
- }
@@ -1 +0,0 @@
1
- export { Mempool } from './Mempool';
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- import { Mempool } from './Mempool';
2
- export { BTCRpcAdapter } from './BTCRpcAdapter';
3
- export const BTCRpcAdapters = {
4
- Mempool,
5
- };
@@ -1,198 +0,0 @@
1
- import * as bitcoin from 'bitcoinjs-lib';
2
- import { Chain } from '../Chain';
3
- import { utils } from '../index.js';
4
- import { parseBTCNetwork } from '../Bitcoin/utils';
5
- /**
6
- * Implementation of the Chain interface for Bitcoin network.
7
- * Handles interactions with both Bitcoin mainnet and testnet, supporting P2WPKH transactions.
8
- */
9
- export class Bitcoin extends Chain {
10
- /**
11
- * Creates a new Bitcoin chain instance
12
- * @param params - Configuration parameters
13
- * @param params.network - Network identifier (mainnet/testnet)
14
- * @param params.contract - Instance of the chain signature contract for MPC operations
15
- * @param params.btcRpcAdapter - Bitcoin RPC adapter for network interactions
16
- */
17
- constructor({ network, contract, btcRpcAdapter, }) {
18
- super();
19
- this.network = network;
20
- this.btcRpcAdapter = btcRpcAdapter;
21
- this.contract = contract;
22
- }
23
- /**
24
- * Converts satoshis to BTC
25
- * @param satoshis - Amount in satoshis
26
- * @returns Amount in BTC
27
- */
28
- static toBTC(satoshis) {
29
- return satoshis / Bitcoin.SATOSHIS_PER_BTC;
30
- }
31
- /**
32
- * Converts BTC to satoshis
33
- * @param btc - Amount in BTC
34
- * @returns Amount in satoshis (rounded)
35
- */
36
- static toSatoshi(btc) {
37
- return Math.round(btc * Bitcoin.SATOSHIS_PER_BTC);
38
- }
39
- async fetchTransaction(transactionId) {
40
- const data = await this.btcRpcAdapter.getTransaction(transactionId);
41
- const tx = new bitcoin.Transaction();
42
- data.vout.forEach((vout) => {
43
- const scriptPubKey = Buffer.from(vout.scriptpubkey, 'hex');
44
- tx.addOutput(scriptPubKey, Number(vout.value));
45
- });
46
- return tx;
47
- }
48
- static parseRSVSignature(signature) {
49
- const r = signature.r.padStart(64, '0');
50
- const s = signature.s.padStart(64, '0');
51
- const rawSignature = Buffer.from(r + s, 'hex');
52
- if (rawSignature.length !== 64) {
53
- throw new Error('Invalid signature length.');
54
- }
55
- return rawSignature;
56
- }
57
- /**
58
- * Creates a Partially Signed Bitcoin Transaction (PSBT)
59
- * @param params - Parameters for creating the PSBT
60
- * @param params.transactionRequest - Transaction request containing inputs and outputs
61
- * @returns Created PSBT instance
62
- */
63
- async createPSBT({ transactionRequest, }) {
64
- const { inputs, outputs } = transactionRequest.inputs && transactionRequest.outputs
65
- ? transactionRequest
66
- : await this.btcRpcAdapter.selectUTXOs(transactionRequest.from, [
67
- {
68
- address: transactionRequest.to,
69
- value: parseFloat(transactionRequest.value),
70
- },
71
- ]);
72
- const psbt = new bitcoin.Psbt({ network: parseBTCNetwork(this.network) });
73
- await Promise.all(inputs.map(async (input) => {
74
- if (!input.scriptPubKey) {
75
- const transaction = await this.fetchTransaction(input.txid);
76
- const prevOut = transaction.outs[input.vout];
77
- input.scriptPubKey = prevOut.script;
78
- }
79
- // Prepare the input as P2WPKH
80
- psbt.addInput({
81
- hash: input.txid,
82
- index: input.vout,
83
- witnessUtxo: {
84
- script: input.scriptPubKey,
85
- value: input.value,
86
- },
87
- });
88
- }));
89
- outputs.forEach((out) => {
90
- if (out.address) {
91
- psbt.addOutput({
92
- address: out.address,
93
- value: out.value,
94
- });
95
- }
96
- else if (out.script) {
97
- psbt.addOutput({
98
- script: out.script,
99
- value: out.value,
100
- });
101
- }
102
- });
103
- return psbt;
104
- }
105
- async getBalance(address) {
106
- const balance = await this.btcRpcAdapter.getBalance(address);
107
- return Bitcoin.toBTC(balance).toString();
108
- }
109
- async deriveAddressAndPublicKey(predecessor, path) {
110
- const uncompressedPubKey = await this.contract.getDerivedPublicKey({
111
- path,
112
- predecessor,
113
- });
114
- if (!uncompressedPubKey) {
115
- throw new Error('Failed to get derived public key');
116
- }
117
- const derivedKey = utils.compressPubKey(uncompressedPubKey);
118
- const publicKeyBuffer = Buffer.from(derivedKey, 'hex');
119
- const network = parseBTCNetwork(this.network);
120
- const payment = bitcoin.payments.p2wpkh({
121
- pubkey: publicKeyBuffer,
122
- network,
123
- });
124
- const { address } = payment;
125
- if (!address) {
126
- throw new Error('Failed to generate Bitcoin address');
127
- }
128
- return { address, publicKey: derivedKey };
129
- }
130
- setTransaction(transaction, storageKey) {
131
- window.localStorage.setItem(storageKey, JSON.stringify({
132
- psbt: transaction.psbt.toHex(),
133
- publicKey: transaction.publicKey,
134
- }));
135
- }
136
- getTransaction(storageKey, options) {
137
- const txSerialized = window.localStorage.getItem(storageKey);
138
- if (!txSerialized)
139
- return undefined;
140
- if (options?.remove) {
141
- window.localStorage.removeItem(storageKey);
142
- }
143
- const transactionJSON = JSON.parse(txSerialized);
144
- return {
145
- psbt: bitcoin.Psbt.fromHex(transactionJSON.psbt),
146
- publicKey: transactionJSON.publicKey,
147
- };
148
- }
149
- async getMPCPayloadAndTransaction(transactionRequest) {
150
- const publicKeyBuffer = Buffer.from(transactionRequest.publicKey, 'hex');
151
- const psbt = await this.createPSBT({
152
- transactionRequest,
153
- });
154
- // We can't double sign a PSBT, therefore we serialize the payload before to return it
155
- const psbtHex = psbt.toHex();
156
- const mpcPayloads = [];
157
- const mockKeyPair = (index) => ({
158
- publicKey: publicKeyBuffer,
159
- sign: (hash) => {
160
- mpcPayloads.push({
161
- index,
162
- payload: Array.from(hash),
163
- });
164
- // Return dummy signature to satisfy the interface
165
- return Buffer.alloc(64);
166
- },
167
- });
168
- for (let index = 0; index < psbt.inputCount; index++) {
169
- psbt.signInput(index, mockKeyPair(index));
170
- }
171
- return {
172
- transaction: {
173
- psbt: bitcoin.Psbt.fromHex(psbtHex),
174
- publicKey: transactionRequest.publicKey,
175
- },
176
- mpcPayloads: mpcPayloads.sort((a, b) => a.index - b.index),
177
- };
178
- }
179
- addSignature({ transaction: { psbt, publicKey }, mpcSignatures, }) {
180
- const publicKeyBuffer = Buffer.from(publicKey, 'hex');
181
- const keyPair = (index) => ({
182
- publicKey: publicKeyBuffer,
183
- sign: () => {
184
- const mpcSignature = mpcSignatures[index];
185
- return Bitcoin.parseRSVSignature(mpcSignature);
186
- },
187
- });
188
- for (let index = 0; index < psbt.inputCount; index++) {
189
- psbt.signInput(index, keyPair(index));
190
- }
191
- psbt.finalizeAllInputs();
192
- return psbt.extractTransaction().toHex();
193
- }
194
- async broadcastTx(txSerialized) {
195
- return await this.btcRpcAdapter.broadcastTransaction(txSerialized);
196
- }
197
- }
198
- Bitcoin.SATOSHIS_PER_BTC = 100000000;
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- import * as bitcoin from 'bitcoinjs-lib';
2
- export function parseBTCNetwork(network) {
3
- switch (network.toLowerCase()) {
4
- case 'mainnet':
5
- return bitcoin.networks.bitcoin;
6
- case 'testnet':
7
- return bitcoin.networks.testnet;
8
- case 'regtest':
9
- return bitcoin.networks.regtest;
10
- default:
11
- throw new Error(`Unknown Bitcoin network: ${network}`);
12
- }
13
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Core interface for blockchain implementations.
3
- * Provides a standardized way to interact with different blockchain networks through a common set of methods.
4
- *
5
- * @typeParam TransactionRequest - The type of transaction request specific to the blockchain
6
- * @typeParam UnsignedTransaction - The type of unsigned transaction specific to the blockchain
7
- */
8
- export class Chain {
9
- }
@@ -1,62 +0,0 @@
1
- import type BN from 'bn.js';
2
- import type { RSVSignature, UncompressedPubKeySEC1 } from './types';
3
- /**
4
- * Arguments for the sign method
5
- */
6
- export interface SignArgs {
7
- /** The payload to sign as an array of 32 bytes */
8
- payload: number[];
9
- /** The derivation path for key generation */
10
- path: string;
11
- /** Version of the key to use */
12
- key_version: number;
13
- }
14
- /**
15
- * Abstract class defining the interface for chain signature contracts.
16
- * This contract handles MPC (Multi-Party Computation) operations for secure key derivation and signing.
17
- * It serves as a bridge between the blockchain implementations and the MPC infrastructure.
18
- */
19
- export declare abstract class ChainSignatureContract {
20
- /**
21
- * Gets the current signature deposit required by the contract.
22
- * This deposit amount helps manage network congestion.
23
- *
24
- * @returns Promise resolving to the required deposit amount as a BigNumber
25
- * @throws Error if the deposit check fails
26
- */
27
- abstract getCurrentSignatureDeposit(): Promise<BN>;
28
- /**
29
- * Gets the public key associated with this contract.
30
- * This is the root public key from which child keys can be derived.
31
- *
32
- * @returns Promise resolving to the uncompressed public key
33
- * @throws Error if public key retrieval fails
34
- */
35
- abstract getPublicKey(): Promise<UncompressedPubKeySEC1>;
36
- /**
37
- * Signs a payload using MPC.
38
- * This is the core signing operation that coordinates with the MPC infrastructure.
39
- *
40
- * @param args - Arguments for the signing operation
41
- * @param args.payload - The data to sign
42
- * @param args.path - Derivation path for the signing key
43
- * @param args.key_version - Version of the key to use
44
- * @returns Promise resolving to the RSV signature
45
- * @throws Error if signing fails or is rejected
46
- */
47
- abstract sign(args: SignArgs & Record<string, unknown>): Promise<RSVSignature>;
48
- /**
49
- * Derives a child public key using a derivation path and predecessor.
50
- * This method implements hierarchical deterministic key derivation.
51
- *
52
- * @param args - Arguments for key derivation
53
- * @param args.path - The derivation path to use
54
- * @param args.predecessor - The predecessor key (usually a NEAR account) that controls this derived key
55
- * @returns Promise resolving to the derived uncompressed public key
56
- * @throws Error if key derivation fails
57
- */
58
- abstract getDerivedPublicKey(args: {
59
- path: string;
60
- predecessor: string;
61
- } & Record<string, unknown>): Promise<UncompressedPubKeySEC1>;
62
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Abstract class defining the interface for chain signature contracts.
3
- * This contract handles MPC (Multi-Party Computation) operations for secure key derivation and signing.
4
- * It serves as a bridge between the blockchain implementations and the MPC infrastructure.
5
- */
6
- export class ChainSignatureContract {
7
- }