signet.js 0.0.1-beta.7 → 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.
- package/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.d.ts +10 -0
- package/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.d.ts +15 -0
- package/chains/Bitcoin/BTCRpcAdapter/Mempool/index.d.ts +1 -0
- package/chains/Bitcoin/BTCRpcAdapter/Mempool/types.d.ts +69 -0
- package/chains/Bitcoin/BTCRpcAdapter/index.d.ts +5 -0
- package/chains/Bitcoin/Bitcoin.d.ts +69 -0
- package/chains/Bitcoin/types.d.ts +42 -0
- package/chains/Bitcoin/utils.d.ts +2 -0
- package/chains/Chain.d.ts +74 -0
- package/chains/ChainSignatureContract.d.ts +41 -0
- package/chains/Cosmos/Cosmos.d.ts +51 -0
- package/chains/Cosmos/types.d.ts +30 -0
- package/chains/Cosmos/utils.d.ts +2 -0
- package/chains/EVM/EVM.d.ts +42 -0
- package/chains/EVM/types.d.ts +5 -0
- package/chains/EVM/utils.d.ts +7 -0
- package/chains/index.d.ts +12 -0
- package/chains/types.d.ts +31 -0
- package/chains/utils.d.ts +12 -0
- package/index.cjs +2 -0
- package/index.cjs.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +2674 -0
- package/index.js.map +1 -0
- package/package.json +2 -2
- package/utils/chains/index.d.ts +1 -0
- package/utils/chains/near/ChainSignatureContract.d.ts +38 -0
- package/utils/chains/near/account.d.ts +13 -0
- package/utils/chains/near/constants.d.ts +3 -0
- package/utils/chains/near/index.d.ts +3 -0
- package/utils/chains/near/relayer/index.d.ts +1 -0
- package/utils/chains/near/relayer/relayer.d.ts +8 -0
- package/utils/chains/near/relayer/types.d.ts +22 -0
- package/utils/chains/near/signAndSend/index.d.ts +1 -0
- package/utils/chains/near/signAndSend/keypair.d.ts +6 -0
- package/utils/chains/near/transactionBuilder.d.ts +26 -0
- package/utils/chains/near/types.d.ts +50 -0
- package/utils/index.d.ts +1 -0
- package/.eslintrc.json +0 -55
- package/.prettierrc +0 -1
- package/babel.config.js +0 -6
- package/docs/pages/chain-signatures-contract.mdx +0 -56
- package/docs/pages/chain.mdx +0 -45
- package/docs/pages/chains/bitcoin/bitcoin.mdx +0 -191
- package/docs/pages/chains/bitcoin/btc-rpc-adapter.mdx +0 -307
- package/docs/pages/chains/cosmos.mdx +0 -181
- package/docs/pages/chains/evm.mdx +0 -189
- package/docs/pages/index.mdx +0 -99
- package/docs/snippets/contract.ts +0 -21
- package/docs/snippets/env.ts +0 -13
- package/jest.config.ts +0 -199
- package/src/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.ts +0 -11
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.ts +0 -96
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/index.ts +0 -1
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/types.ts +0 -72
- package/src/chains/Bitcoin/BTCRpcAdapter/index.ts +0 -6
- package/src/chains/Bitcoin/Bitcoin.ts +0 -301
- package/src/chains/Bitcoin/types.ts +0 -45
- package/src/chains/Bitcoin/utils.ts +0 -14
- package/src/chains/Chain.ts +0 -96
- package/src/chains/ChainSignatureContract.ts +0 -48
- package/src/chains/Cosmos/Cosmos.ts +0 -279
- package/src/chains/Cosmos/types.ts +0 -35
- package/src/chains/Cosmos/utils.ts +0 -45
- package/src/chains/EVM/EVM.ts +0 -180
- package/src/chains/EVM/types.ts +0 -7
- package/src/chains/EVM/utils.ts +0 -26
- package/src/chains/index.ts +0 -34
- package/src/chains/types.ts +0 -35
- package/src/chains/utils.ts +0 -40
- package/src/index.ts +0 -2
- package/src/utils/chains/index.ts +0 -1
- package/src/utils/chains/near/ChainSignatureContract.ts +0 -195
- package/src/utils/chains/near/account.ts +0 -42
- package/src/utils/chains/near/constants.ts +0 -4
- package/src/utils/chains/near/index.ts +0 -3
- package/src/utils/chains/near/relayer/index.ts +0 -1
- package/src/utils/chains/near/relayer/relayer.ts +0 -39
- package/src/utils/chains/near/relayer/types.ts +0 -24
- package/src/utils/chains/near/signAndSend/index.ts +0 -1
- package/src/utils/chains/near/signAndSend/keypair.ts +0 -180
- package/src/utils/chains/near/transactionBuilder.ts +0 -138
- package/src/utils/chains/near/types.ts +0 -67
- package/src/utils/index.ts +0 -1
- package/tsconfig.eslint.json +0 -8
- package/tsconfig.json +0 -116
- package/vite.config.ts +0 -47
- package/vocs.config.ts +0 -60
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
import * as bitcoin from 'bitcoinjs-lib'
|
|
2
|
-
|
|
3
|
-
import { utils } from '@chains'
|
|
4
|
-
import { type BTCRpcAdapter } from '@chains/Bitcoin/BTCRpcAdapter'
|
|
5
|
-
import type {
|
|
6
|
-
BTCInput,
|
|
7
|
-
BTCNetworkIds,
|
|
8
|
-
BTCOutput,
|
|
9
|
-
BTCTransactionRequest,
|
|
10
|
-
BTCUnsignedTransaction,
|
|
11
|
-
} from '@chains/Bitcoin/types'
|
|
12
|
-
import { parseBTCNetwork } from '@chains/Bitcoin/utils'
|
|
13
|
-
import { Chain } from '@chains/Chain'
|
|
14
|
-
import type { ChainSignatureContract } from '@chains/ChainSignatureContract'
|
|
15
|
-
import type {
|
|
16
|
-
MPCPayloads,
|
|
17
|
-
RSVSignature,
|
|
18
|
-
KeyDerivationPath,
|
|
19
|
-
} from '@chains/types'
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Implementation of the Chain interface for Bitcoin network.
|
|
23
|
-
* Handles interactions with both Bitcoin mainnet and testnet, supporting P2WPKH transactions.
|
|
24
|
-
*/
|
|
25
|
-
export class Bitcoin extends Chain<
|
|
26
|
-
BTCTransactionRequest,
|
|
27
|
-
BTCUnsignedTransaction
|
|
28
|
-
> {
|
|
29
|
-
private static readonly SATOSHIS_PER_BTC = 100_000_000
|
|
30
|
-
|
|
31
|
-
private readonly network: BTCNetworkIds
|
|
32
|
-
private readonly btcRpcAdapter: BTCRpcAdapter
|
|
33
|
-
private readonly contract: ChainSignatureContract
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Creates a new Bitcoin chain instance
|
|
37
|
-
* @param params - Configuration parameters
|
|
38
|
-
* @param params.network - Network identifier (mainnet/testnet)
|
|
39
|
-
* @param params.contract - Instance of the chain signature contract for MPC operations
|
|
40
|
-
* @param params.btcRpcAdapter - Bitcoin RPC adapter for network interactions
|
|
41
|
-
*/
|
|
42
|
-
constructor({
|
|
43
|
-
network,
|
|
44
|
-
contract,
|
|
45
|
-
btcRpcAdapter,
|
|
46
|
-
}: {
|
|
47
|
-
network: BTCNetworkIds
|
|
48
|
-
contract: ChainSignatureContract
|
|
49
|
-
btcRpcAdapter: BTCRpcAdapter
|
|
50
|
-
}) {
|
|
51
|
-
super()
|
|
52
|
-
|
|
53
|
-
this.network = network
|
|
54
|
-
this.btcRpcAdapter = btcRpcAdapter
|
|
55
|
-
this.contract = contract
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Converts satoshis to BTC
|
|
60
|
-
* @param satoshis - Amount in satoshis
|
|
61
|
-
* @returns Amount in BTC
|
|
62
|
-
*/
|
|
63
|
-
static toBTC(satoshis: number): number {
|
|
64
|
-
return satoshis / Bitcoin.SATOSHIS_PER_BTC
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Converts BTC to satoshis
|
|
69
|
-
* @param btc - Amount in BTC
|
|
70
|
-
* @returns Amount in satoshis (rounded)
|
|
71
|
-
*/
|
|
72
|
-
static toSatoshi(btc: number): number {
|
|
73
|
-
return Math.round(btc * Bitcoin.SATOSHIS_PER_BTC)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private async fetchTransaction(
|
|
77
|
-
transactionId: string
|
|
78
|
-
): Promise<bitcoin.Transaction> {
|
|
79
|
-
const data = await this.btcRpcAdapter.getTransaction(transactionId)
|
|
80
|
-
const tx = new bitcoin.Transaction()
|
|
81
|
-
|
|
82
|
-
data.vout.forEach((vout) => {
|
|
83
|
-
const scriptPubKey = Buffer.from(vout.scriptpubkey, 'hex')
|
|
84
|
-
tx.addOutput(scriptPubKey, Number(vout.value))
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
return tx
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
private static parseRSVSignature(signature: RSVSignature): Buffer {
|
|
91
|
-
const r = signature.r.padStart(64, '0')
|
|
92
|
-
const s = signature.s.padStart(64, '0')
|
|
93
|
-
|
|
94
|
-
const rawSignature = Buffer.from(r + s, 'hex')
|
|
95
|
-
|
|
96
|
-
if (rawSignature.length !== 64) {
|
|
97
|
-
throw new Error('Invalid signature length.')
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return rawSignature
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Creates a Partially Signed Bitcoin Transaction (PSBT)
|
|
105
|
-
* @param params - Parameters for creating the PSBT
|
|
106
|
-
* @param params.transactionRequest - Transaction request containing inputs and outputs
|
|
107
|
-
* @returns Created PSBT instance
|
|
108
|
-
*/
|
|
109
|
-
async createPSBT({
|
|
110
|
-
transactionRequest,
|
|
111
|
-
}: {
|
|
112
|
-
transactionRequest: BTCTransactionRequest
|
|
113
|
-
}): Promise<bitcoin.Psbt> {
|
|
114
|
-
const { inputs, outputs } =
|
|
115
|
-
transactionRequest.inputs && transactionRequest.outputs
|
|
116
|
-
? transactionRequest
|
|
117
|
-
: await this.btcRpcAdapter.selectUTXOs(transactionRequest.from, [
|
|
118
|
-
{
|
|
119
|
-
address: transactionRequest.to,
|
|
120
|
-
value: parseFloat(transactionRequest.value),
|
|
121
|
-
},
|
|
122
|
-
])
|
|
123
|
-
|
|
124
|
-
const psbt = new bitcoin.Psbt({ network: parseBTCNetwork(this.network) })
|
|
125
|
-
|
|
126
|
-
await Promise.all(
|
|
127
|
-
inputs.map(async (input: BTCInput) => {
|
|
128
|
-
if (!input.scriptPubKey) {
|
|
129
|
-
const transaction = await this.fetchTransaction(input.txid)
|
|
130
|
-
const prevOut = transaction.outs[input.vout]
|
|
131
|
-
input.scriptPubKey = prevOut.script
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Prepare the input as P2WPKH
|
|
135
|
-
psbt.addInput({
|
|
136
|
-
hash: input.txid,
|
|
137
|
-
index: input.vout,
|
|
138
|
-
witnessUtxo: {
|
|
139
|
-
script: input.scriptPubKey,
|
|
140
|
-
value: input.value,
|
|
141
|
-
},
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
outputs.forEach((out: BTCOutput) => {
|
|
147
|
-
if (out.address) {
|
|
148
|
-
psbt.addOutput({
|
|
149
|
-
address: out.address,
|
|
150
|
-
value: out.value,
|
|
151
|
-
})
|
|
152
|
-
} else if (out.script) {
|
|
153
|
-
psbt.addOutput({
|
|
154
|
-
script: out.script,
|
|
155
|
-
value: out.value,
|
|
156
|
-
})
|
|
157
|
-
}
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
return psbt
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
async getBalance(address: string): Promise<string> {
|
|
164
|
-
const balance = await this.btcRpcAdapter.getBalance(address)
|
|
165
|
-
return Bitcoin.toBTC(balance).toString()
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
async deriveAddressAndPublicKey(
|
|
169
|
-
predecessor: string,
|
|
170
|
-
path: KeyDerivationPath
|
|
171
|
-
): Promise<{ address: string; publicKey: string }> {
|
|
172
|
-
const uncompressedPubKey = await this.contract.getDerivedPublicKey({
|
|
173
|
-
path,
|
|
174
|
-
predecessor,
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
if (!uncompressedPubKey) {
|
|
178
|
-
throw new Error('Failed to get derived public key')
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const derivedKey = utils.compressPubKey(uncompressedPubKey)
|
|
182
|
-
const publicKeyBuffer = Buffer.from(derivedKey, 'hex')
|
|
183
|
-
const network = parseBTCNetwork(this.network)
|
|
184
|
-
|
|
185
|
-
const payment = bitcoin.payments.p2wpkh({
|
|
186
|
-
pubkey: publicKeyBuffer,
|
|
187
|
-
network,
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
const { address } = payment
|
|
191
|
-
|
|
192
|
-
if (!address) {
|
|
193
|
-
throw new Error('Failed to generate Bitcoin address')
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return { address, publicKey: derivedKey }
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
setTransaction(
|
|
200
|
-
transaction: BTCUnsignedTransaction,
|
|
201
|
-
storageKey: string
|
|
202
|
-
): void {
|
|
203
|
-
window.localStorage.setItem(
|
|
204
|
-
storageKey,
|
|
205
|
-
JSON.stringify({
|
|
206
|
-
psbt: transaction.psbt.toHex(),
|
|
207
|
-
publicKey: transaction.publicKey,
|
|
208
|
-
})
|
|
209
|
-
)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
getTransaction(
|
|
213
|
-
storageKey: string,
|
|
214
|
-
options?: {
|
|
215
|
-
remove?: boolean
|
|
216
|
-
}
|
|
217
|
-
): BTCUnsignedTransaction | undefined {
|
|
218
|
-
const txSerialized = window.localStorage.getItem(storageKey)
|
|
219
|
-
if (!txSerialized) return undefined
|
|
220
|
-
|
|
221
|
-
if (options?.remove) {
|
|
222
|
-
window.localStorage.removeItem(storageKey)
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const transactionJSON = JSON.parse(txSerialized)
|
|
226
|
-
return {
|
|
227
|
-
psbt: bitcoin.Psbt.fromHex(transactionJSON.psbt as string),
|
|
228
|
-
publicKey: transactionJSON.publicKey,
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
async getMPCPayloadAndTransaction(
|
|
233
|
-
transactionRequest: BTCTransactionRequest
|
|
234
|
-
): Promise<{
|
|
235
|
-
transaction: BTCUnsignedTransaction
|
|
236
|
-
mpcPayloads: MPCPayloads
|
|
237
|
-
}> {
|
|
238
|
-
const publicKeyBuffer = Buffer.from(transactionRequest.publicKey, 'hex')
|
|
239
|
-
const psbt = await this.createPSBT({
|
|
240
|
-
transactionRequest,
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
// We can't double sign a PSBT, therefore we serialize the payload before to return it
|
|
244
|
-
const psbtHex = psbt.toHex()
|
|
245
|
-
|
|
246
|
-
const mpcPayloads: MPCPayloads = []
|
|
247
|
-
|
|
248
|
-
const mockKeyPair = (index: number): bitcoin.Signer => ({
|
|
249
|
-
publicKey: publicKeyBuffer,
|
|
250
|
-
sign: (hash: Buffer): Buffer => {
|
|
251
|
-
mpcPayloads.push({
|
|
252
|
-
index,
|
|
253
|
-
payload: Array.from(hash),
|
|
254
|
-
})
|
|
255
|
-
// Return dummy signature to satisfy the interface
|
|
256
|
-
return Buffer.alloc(64)
|
|
257
|
-
},
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
for (let index = 0; index < psbt.inputCount; index++) {
|
|
261
|
-
psbt.signInput(index, mockKeyPair(index))
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return {
|
|
265
|
-
transaction: {
|
|
266
|
-
psbt: bitcoin.Psbt.fromHex(psbtHex),
|
|
267
|
-
publicKey: transactionRequest.publicKey,
|
|
268
|
-
},
|
|
269
|
-
mpcPayloads: mpcPayloads.sort((a, b) => a.index - b.index),
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
addSignature({
|
|
274
|
-
transaction: { psbt, publicKey },
|
|
275
|
-
mpcSignatures,
|
|
276
|
-
}: {
|
|
277
|
-
transaction: BTCUnsignedTransaction
|
|
278
|
-
mpcSignatures: RSVSignature[]
|
|
279
|
-
}): string {
|
|
280
|
-
const publicKeyBuffer = Buffer.from(publicKey, 'hex')
|
|
281
|
-
|
|
282
|
-
const keyPair = (index: number): bitcoin.Signer => ({
|
|
283
|
-
publicKey: publicKeyBuffer,
|
|
284
|
-
sign: () => {
|
|
285
|
-
const mpcSignature = mpcSignatures[index]
|
|
286
|
-
return Bitcoin.parseRSVSignature(mpcSignature)
|
|
287
|
-
},
|
|
288
|
-
})
|
|
289
|
-
|
|
290
|
-
for (let index = 0; index < psbt.inputCount; index++) {
|
|
291
|
-
psbt.signInput(index, keyPair(index))
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
psbt.finalizeAllInputs()
|
|
295
|
-
return psbt.extractTransaction().toHex()
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
async broadcastTx(txSerialized: string): Promise<string> {
|
|
299
|
-
return await this.btcRpcAdapter.broadcastTransaction(txSerialized)
|
|
300
|
-
}
|
|
301
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type * as bitcoin from 'bitcoinjs-lib'
|
|
2
|
-
|
|
3
|
-
export interface BTCTransaction {
|
|
4
|
-
vout: Array<{
|
|
5
|
-
scriptpubkey: string
|
|
6
|
-
value: number
|
|
7
|
-
}>
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface BTCInput {
|
|
11
|
-
txid: string
|
|
12
|
-
vout: number
|
|
13
|
-
value: number
|
|
14
|
-
scriptPubKey: Buffer
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type BTCOutput = {
|
|
18
|
-
value: number
|
|
19
|
-
} & ({ address: string; script?: never } | { address?: never; script: Buffer })
|
|
20
|
-
|
|
21
|
-
export type BTCTransactionRequest = {
|
|
22
|
-
publicKey: string
|
|
23
|
-
} & (
|
|
24
|
-
| {
|
|
25
|
-
inputs: BTCInput[]
|
|
26
|
-
outputs: BTCOutput[]
|
|
27
|
-
from?: never
|
|
28
|
-
to?: never
|
|
29
|
-
value?: never
|
|
30
|
-
}
|
|
31
|
-
| {
|
|
32
|
-
inputs?: never
|
|
33
|
-
outputs?: never
|
|
34
|
-
from: string
|
|
35
|
-
to: string
|
|
36
|
-
value: string
|
|
37
|
-
}
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
export interface BTCUnsignedTransaction {
|
|
41
|
-
psbt: bitcoin.Psbt
|
|
42
|
-
publicKey: string
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export type BTCNetworkIds = 'mainnet' | 'testnet' | 'regtest'
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as bitcoin from 'bitcoinjs-lib'
|
|
2
|
-
|
|
3
|
-
export function parseBTCNetwork(network: string): bitcoin.networks.Network {
|
|
4
|
-
switch (network.toLowerCase()) {
|
|
5
|
-
case 'mainnet':
|
|
6
|
-
return bitcoin.networks.bitcoin
|
|
7
|
-
case 'testnet':
|
|
8
|
-
return bitcoin.networks.testnet
|
|
9
|
-
case 'regtest':
|
|
10
|
-
return bitcoin.networks.regtest
|
|
11
|
-
default:
|
|
12
|
-
throw new Error(`Unknown Bitcoin network: ${network}`)
|
|
13
|
-
}
|
|
14
|
-
}
|
package/src/chains/Chain.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
KeyDerivationPath,
|
|
3
|
-
MPCPayloads,
|
|
4
|
-
RSVSignature,
|
|
5
|
-
} from '@chains/types'
|
|
6
|
-
|
|
7
|
-
export abstract class Chain<TransactionRequest, UnsignedTransaction> {
|
|
8
|
-
/**
|
|
9
|
-
* Gets the native token balance for a given address
|
|
10
|
-
*
|
|
11
|
-
* @param address - The address to check
|
|
12
|
-
* @returns Promise resolving to the balance as a string, formatted according to the chain's decimal places (e.g. ETH, BTC, etc.)
|
|
13
|
-
*/
|
|
14
|
-
abstract getBalance(address: string): Promise<string>
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Uses Sig Network Key Derivation Function to derive the address and public key. from a signer ID and string path.
|
|
18
|
-
*
|
|
19
|
-
* @param predecessor - The id/address of the account requesting signature
|
|
20
|
-
* @param path - The string path used to derive the key
|
|
21
|
-
* @returns Promise resolving to the derived address and public key
|
|
22
|
-
*/
|
|
23
|
-
abstract deriveAddressAndPublicKey(
|
|
24
|
-
predecessor: string,
|
|
25
|
-
path: KeyDerivationPath
|
|
26
|
-
): Promise<{
|
|
27
|
-
address: string
|
|
28
|
-
publicKey: string
|
|
29
|
-
}>
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Stores an unsigned transaction in local storage for later use.
|
|
33
|
-
* Particularly useful for browser-based wallets that redirects the user to a different page.
|
|
34
|
-
*
|
|
35
|
-
* @param transaction - The unsigned transaction to store
|
|
36
|
-
* @param storageKey - Unique key to identify the stored transaction
|
|
37
|
-
*/
|
|
38
|
-
abstract setTransaction(
|
|
39
|
-
transaction: UnsignedTransaction,
|
|
40
|
-
storageKey: string
|
|
41
|
-
): void
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Retrieves a previously stored transaction from local storage.
|
|
45
|
-
*
|
|
46
|
-
* @param storageKey - The key used to store the transaction
|
|
47
|
-
* @param options - Additional options
|
|
48
|
-
* @param options.remove - If true, removes the transaction from storage after retrieval
|
|
49
|
-
* @returns The stored transaction or undefined if not found
|
|
50
|
-
*/
|
|
51
|
-
abstract getTransaction(
|
|
52
|
-
storageKey: string,
|
|
53
|
-
options?: {
|
|
54
|
-
remove?: boolean
|
|
55
|
-
}
|
|
56
|
-
): UnsignedTransaction | undefined
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Prepares a transaction for Sig Network MPC signing by creating the necessary payloads.
|
|
60
|
-
* This method handles chain-specific transaction preparation including:
|
|
61
|
-
* - Fee calculation
|
|
62
|
-
* - Nonce/sequence management
|
|
63
|
-
* - UTXO selection (for UTXO-based chains)
|
|
64
|
-
* - Transaction encoding
|
|
65
|
-
*
|
|
66
|
-
* @param transactionRequest - The transaction request containing parameters like recipient, amount, etc.
|
|
67
|
-
* @returns Promise resolving to the unsigned transaction and MPC payloads for signing
|
|
68
|
-
*/
|
|
69
|
-
abstract getMPCPayloadAndTransaction(
|
|
70
|
-
transactionRequest: TransactionRequest
|
|
71
|
-
): Promise<{
|
|
72
|
-
transaction: UnsignedTransaction
|
|
73
|
-
mpcPayloads: MPCPayloads
|
|
74
|
-
}>
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Adds Sig Network MPC-generated signatures to an unsigned transaction.
|
|
78
|
-
*
|
|
79
|
-
* @param params - Parameters for adding signatures
|
|
80
|
-
* @param params.transaction - The unsigned transaction to add signatures to
|
|
81
|
-
* @param params.mpcSignatures - Array of RSV signatures generated through MPC
|
|
82
|
-
* @returns The serialized signed transaction ready for broadcast
|
|
83
|
-
*/
|
|
84
|
-
abstract addSignature(params: {
|
|
85
|
-
transaction: UnsignedTransaction
|
|
86
|
-
mpcSignatures: RSVSignature[]
|
|
87
|
-
}): string
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Broadcasts a signed transaction to the network.
|
|
91
|
-
*
|
|
92
|
-
* @param txSerialized - The serialized signed transaction
|
|
93
|
-
* @returns Promise resolving to the transaction hash/ID
|
|
94
|
-
*/
|
|
95
|
-
abstract broadcastTx(txSerialized: string): Promise<string>
|
|
96
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type BN from 'bn.js'
|
|
2
|
-
|
|
3
|
-
import type { RSVSignature, UncompressedPubKeySEC1 } from '@chains/types'
|
|
4
|
-
|
|
5
|
-
export interface SignArgs {
|
|
6
|
-
/** The payload to sign as an array of 32 bytes */
|
|
7
|
-
payload: number[]
|
|
8
|
-
/** The derivation path for key generation */
|
|
9
|
-
path: string
|
|
10
|
-
/** Version of the key to use */
|
|
11
|
-
key_version: number
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export abstract class ChainSignatureContract {
|
|
15
|
-
/**
|
|
16
|
-
* Gets the current signature deposit required by the contract.
|
|
17
|
-
* This deposit amount helps manage network congestion.
|
|
18
|
-
*
|
|
19
|
-
* @returns Promise resolving to the required deposit amount as a BigNumber
|
|
20
|
-
*/
|
|
21
|
-
abstract getCurrentSignatureDeposit(): Promise<BN>
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Signs a payload using Sig Network MPC.
|
|
25
|
-
*
|
|
26
|
-
* @param args - Arguments for the signing operation
|
|
27
|
-
* @param args.payload - The data to sign as an array of 32 bytes
|
|
28
|
-
* @param args.path - The string path to use derive the key
|
|
29
|
-
* @param args.key_version - Version of the key to use
|
|
30
|
-
* @returns Promise resolving to the RSV signature
|
|
31
|
-
*/
|
|
32
|
-
abstract sign(args: SignArgs & Record<string, unknown>): Promise<RSVSignature>
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Derives a child public key using a derivation path and predecessor.
|
|
36
|
-
*
|
|
37
|
-
* @param args - Arguments for key derivation
|
|
38
|
-
* @param args.path - The string path to use derive the key
|
|
39
|
-
* @param args.predecessor - The id/address of the account requesting signature
|
|
40
|
-
* @returns Promise resolving to the derived SEC1 uncompressed public key
|
|
41
|
-
*/
|
|
42
|
-
abstract getDerivedPublicKey(
|
|
43
|
-
args: {
|
|
44
|
-
path: string
|
|
45
|
-
predecessor: string
|
|
46
|
-
} & Record<string, unknown>
|
|
47
|
-
): Promise<UncompressedPubKeySEC1>
|
|
48
|
-
}
|