signet.js 0.0.7 → 0.0.9-retry
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/README.md +8 -1
- package/browser/index.browser.cjs +3 -0
- package/browser/index.browser.cjs.map +1 -0
- package/browser/index.browser.js +3 -0
- package/browser/index.browser.js.map +1 -0
- package/node/index.node.cjs +3 -0
- package/node/index.node.cjs.map +1 -0
- package/node/index.node.js +3 -0
- package/node/index.node.js.map +1 -0
- package/package.json +19 -18
- package/types/index.d.cts +1048 -0
- package/types/index.d.ts +1048 -0
- package/.eslintrc.json +0 -67
- package/.prettierrc +0 -1
- package/babel.config.js +0 -6
- package/docs/dist/.vocs/icons/arrow-diagonal.svg +0 -3
- package/docs/dist/.vocs/icons/chevron-down.svg +0 -13
- package/docs/dist/.vocs/icons/chevron-up.svg +0 -13
- package/docs/dist/.vocs/icons/link.svg +0 -3
- package/docs/dist/.vocs/search-index-7b499e25.json +0 -1
- package/docs/dist/assets/arbitrary-hash-Cd6eo8ZD.js +0 -309
- package/docs/dist/assets/broadcast-tx-CeTEE9yX.js +0 -8
- package/docs/dist/assets/btc-rpc-adapter-C-qSHpFV.js +0 -226
- package/docs/dist/assets/chain-adapter-interface-B9TpOgQv.js +0 -1280
- package/docs/dist/assets/chain-contract-interface-DEku3k45.js +0 -392
- package/docs/dist/assets/constructor-73n7bp3b.js +0 -161
- package/docs/dist/assets/constructor-Bg7nvLe0.js +0 -14
- package/docs/dist/assets/contract-addresses-BYlrAOs3.js +0 -200
- package/docs/dist/assets/derive-address-and-public-key-DExrKiGV.js +0 -14
- package/docs/dist/assets/finalize-message-signing-W435d71R.js +0 -20
- package/docs/dist/assets/finalize-transaction-signing-BIgJ2dnc.js +0 -36
- package/docs/dist/assets/finalize-transaction-signing-C--HJs8D.js +0 -24
- package/docs/dist/assets/finalize-transaction-signing-CjGmN7d9.js +0 -24
- package/docs/dist/assets/finalize-typed-data-signing-CEOp_GWt.js +0 -21
- package/docs/dist/assets/get-balance-DBC-i6KG.js +0 -13
- package/docs/dist/assets/get-current-signature-deposit-BXm9AzYy.js +0 -6
- package/docs/dist/assets/get-current-signature-deposit-nOw4j1MN.js +0 -6
- package/docs/dist/assets/get-derived-public-key-BXvfo2m2.js +0 -14
- package/docs/dist/assets/get-derived-public-key-DQ1pyiFS.js +0 -14
- package/docs/dist/assets/get-latest-key-version-DWlkMCre.js +0 -6
- package/docs/dist/assets/get-public-key-B4PFoVqu.js +0 -6
- package/docs/dist/assets/get-public-key-B9xkYkD_.js +0 -6
- package/docs/dist/assets/index-BFuwoY4w.js +0 -601
- package/docs/dist/assets/index-C62Mf-vy.js +0 -426
- package/docs/dist/assets/index-D8xhaiVb.js +0 -121
- package/docs/dist/assets/index-DTr0DlO0.js +0 -36
- package/docs/dist/assets/index-V9dXf-ik.js +0 -457
- package/docs/dist/assets/prepare-message-for-signing-DESTq-Hg.js +0 -16
- package/docs/dist/assets/prepare-transaction-for-signing-DIKTU0zj.js +0 -33
- package/docs/dist/assets/prepare-transaction-for-signing-DV_wkZ5g.js +0 -21
- package/docs/dist/assets/prepare-transaction-for-signing-LVDP0COu.js +0 -33
- package/docs/dist/assets/prepare-typed-data-for-signing-CWcmJvw0.js +0 -192
- package/docs/dist/assets/sign-CwtS5LnB.js +0 -13
- package/docs/dist/assets/sign-OQxf9yn7.js +0 -15
- package/docs/dist/assets/signet-quick-start-CQK52nVG.js +0 -350
- package/docs/dist/assets/sponsor-foreign-chain-gas-C9iWXM8Q.js +0 -1
- package/docs/dist/assets/style-CKGXuRqx.css +0 -1
- package/docs/dist/examples/arbitrary-hash/index.html +0 -88
- package/docs/dist/examples/sponsor-foreign-chain-gas/index.html +0 -21
- package/docs/dist/index.html +0 -56
- package/docs/dist/initializeTheme.iife.js +0 -1
- package/docs/dist/introduction/signet-quick-start/index.html +0 -109
- package/docs/dist/primitives/chain-adapter-interface/index.html +0 -515
- package/docs/dist/primitives/chain-contract-interface/index.html +0 -306
- package/docs/dist/primitives/contract-addresses/index.html +0 -97
- package/docs/dist/signet-logo.png +0 -0
- package/docs/dist/signetjs/chain-adapters/bitcoin/btc-rpc-adapter/index.html +0 -148
- package/docs/dist/signetjs/chain-adapters/bitcoin/finalize-transaction-signing/index.html +0 -41
- package/docs/dist/signetjs/chain-adapters/bitcoin/index.html +0 -187
- package/docs/dist/signetjs/chain-adapters/bitcoin/prepare-transaction-for-signing/index.html +0 -34
- package/docs/dist/signetjs/chain-adapters/broadcast-tx/index.html +0 -28
- package/docs/dist/signetjs/chain-adapters/cosmos/finalize-transaction-signing/index.html +0 -41
- package/docs/dist/signetjs/chain-adapters/cosmos/index.html +0 -166
- package/docs/dist/signetjs/chain-adapters/cosmos/prepare-transaction-for-signing/index.html +0 -43
- package/docs/dist/signetjs/chain-adapters/derive-address-and-public-key/index.html +0 -31
- package/docs/dist/signetjs/chain-adapters/evm/finalize-message-signing/index.html +0 -38
- package/docs/dist/signetjs/chain-adapters/evm/finalize-transaction-signing/index.html +0 -41
- package/docs/dist/signetjs/chain-adapters/evm/finalize-typed-data-signing/index.html +0 -39
- package/docs/dist/signetjs/chain-adapters/evm/index.html +0 -129
- package/docs/dist/signetjs/chain-adapters/evm/prepare-message-for-signing/index.html +0 -31
- package/docs/dist/signetjs/chain-adapters/evm/prepare-transaction-for-signing/index.html +0 -34
- package/docs/dist/signetjs/chain-adapters/evm/prepare-typed-data-for-signing/index.html +0 -49
- package/docs/dist/signetjs/chain-adapters/get-balance/index.html +0 -30
- package/docs/dist/signetjs/contracts/evm/constructor/index.html +0 -45
- package/docs/dist/signetjs/contracts/evm/get-current-signature-deposit/index.html +0 -26
- package/docs/dist/signetjs/contracts/evm/get-derived-public-key/index.html +0 -31
- package/docs/dist/signetjs/contracts/evm/get-latest-key-version/index.html +0 -26
- package/docs/dist/signetjs/contracts/evm/get-public-key/index.html +0 -26
- package/docs/dist/signetjs/contracts/evm/sign/index.html +0 -32
- package/docs/dist/signetjs/contracts/near/constructor/index.html +0 -34
- package/docs/dist/signetjs/contracts/near/get-current-signature-deposit/index.html +0 -26
- package/docs/dist/signetjs/contracts/near/get-derived-public-key/index.html +0 -31
- package/docs/dist/signetjs/contracts/near/get-public-key/index.html +0 -26
- package/docs/dist/signetjs/contracts/near/sign/index.html +0 -32
- package/docs/pages/examples/arbitrary-hash.mdx +0 -73
- package/docs/pages/examples/sponsor-foreign-chain-gas.mdx +0 -1
- package/docs/pages/index.mdx +0 -36
- package/docs/pages/introduction/signet-quick-start.mdx +0 -88
- package/docs/pages/primitives/chain-adapter-interface.mdx +0 -45
- package/docs/pages/primitives/chain-contract-interface.mdx +0 -52
- package/docs/pages/primitives/contract-addresses.mdx +0 -27
- package/docs/pages/signetjs/chain-adapters/bitcoin/btc-rpc-adapter.mdx +0 -26
- package/docs/pages/signetjs/chain-adapters/bitcoin/finalize-transaction-signing.mdx +0 -47
- package/docs/pages/signetjs/chain-adapters/bitcoin/index.mdx +0 -119
- package/docs/pages/signetjs/chain-adapters/bitcoin/prepare-transaction-for-signing.mdx +0 -30
- package/docs/pages/signetjs/chain-adapters/broadcast-tx.mdx +0 -23
- package/docs/pages/signetjs/chain-adapters/cosmos/finalize-transaction-signing.mdx +0 -53
- package/docs/pages/signetjs/chain-adapters/cosmos/index.mdx +0 -108
- package/docs/pages/signetjs/chain-adapters/cosmos/prepare-transaction-for-signing.mdx +0 -39
- package/docs/pages/signetjs/chain-adapters/derive-address-and-public-key.mdx +0 -28
- package/docs/pages/signetjs/chain-adapters/evm/finalize-message-signing.mdx +0 -33
- package/docs/pages/signetjs/chain-adapters/evm/finalize-transaction-signing.mdx +0 -44
- package/docs/pages/signetjs/chain-adapters/evm/finalize-typed-data-signing.mdx +0 -34
- package/docs/pages/signetjs/chain-adapters/evm/index.mdx +0 -84
- package/docs/pages/signetjs/chain-adapters/evm/prepare-message-for-signing.mdx +0 -26
- package/docs/pages/signetjs/chain-adapters/evm/prepare-transaction-for-signing.mdx +0 -30
- package/docs/pages/signetjs/chain-adapters/evm/prepare-typed-data-for-signing.mdx +0 -44
- package/docs/pages/signetjs/chain-adapters/get-balance.mdx +0 -26
- package/docs/pages/signetjs/contracts/evm/constructor.mdx +0 -38
- package/docs/pages/signetjs/contracts/evm/get-current-signature-deposit.mdx +0 -17
- package/docs/pages/signetjs/contracts/evm/get-derived-public-key.mdx +0 -28
- package/docs/pages/signetjs/contracts/evm/get-latest-key-version.mdx +0 -17
- package/docs/pages/signetjs/contracts/evm/get-public-key.mdx +0 -17
- package/docs/pages/signetjs/contracts/evm/sign.mdx +0 -36
- package/docs/pages/signetjs/contracts/near/constructor.mdx +0 -29
- package/docs/pages/signetjs/contracts/near/get-current-signature-deposit.mdx +0 -17
- package/docs/pages/signetjs/contracts/near/get-derived-public-key.mdx +0 -28
- package/docs/pages/signetjs/contracts/near/get-public-key.mdx +0 -17
- package/docs/pages/signetjs/contracts/near/sign.mdx +0 -32
- package/docs/public/signet-logo.png +0 -0
- package/docs/snippets/code/chains.ts +0 -42
- package/docs/snippets/code/contract.ts +0 -44
- package/docs/snippets/code/evm/contract.ts +0 -24
- package/docs/snippets/code/evm/env.ts +0 -16
- package/docs/snippets/code/near/env.ts +0 -13
- package/hardhat.config.mts +0 -19
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.ts +0 -15
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/Mempool.ts +0 -101
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/index.ts +0 -1
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/types.ts +0 -72
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/index.ts +0 -6
- package/src/chain-adapters/Bitcoin/Bitcoin.ts +0 -287
- package/src/chain-adapters/Bitcoin/index.ts +0 -13
- package/src/chain-adapters/Bitcoin/types.ts +0 -48
- package/src/chain-adapters/Bitcoin/utils.ts +0 -14
- package/src/chain-adapters/ChainAdapter.ts +0 -92
- package/src/chain-adapters/Cosmos/Cosmos.ts +0 -258
- package/src/chain-adapters/Cosmos/index.ts +0 -8
- package/src/chain-adapters/Cosmos/types.ts +0 -35
- package/src/chain-adapters/Cosmos/utils.ts +0 -45
- package/src/chain-adapters/EVM/EVM.test.ts +0 -238
- package/src/chain-adapters/EVM/EVM.ts +0 -337
- package/src/chain-adapters/EVM/index.ts +0 -11
- package/src/chain-adapters/EVM/types.ts +0 -53
- package/src/chain-adapters/EVM/utils.ts +0 -27
- package/src/chain-adapters/index.ts +0 -5
- package/src/constants.ts +0 -62
- package/src/contracts/ChainSignatureContract.ts +0 -65
- package/src/contracts/evm/ChainSignaturesContract.ts +0 -323
- package/src/contracts/evm/ChainSignaturesContractABI.ts +0 -359
- package/src/contracts/evm/errors.ts +0 -52
- package/src/contracts/evm/index.ts +0 -10
- package/src/contracts/evm/types.ts +0 -39
- package/src/contracts/evm/utils.ts +0 -41
- package/src/contracts/index.ts +0 -4
- package/src/contracts/near/ChainSignatureContract.ts +0 -196
- package/src/contracts/near/account.ts +0 -42
- package/src/contracts/near/constants.ts +0 -4
- package/src/contracts/near/index.ts +0 -10
- package/src/contracts/near/signAndSend/index.ts +0 -1
- package/src/contracts/near/signAndSend/keypair.ts +0 -178
- package/src/contracts/near/transaction.ts +0 -202
- package/src/contracts/near/types.ts +0 -71
- package/src/index.ts +0 -5
- package/src/types.ts +0 -46
- package/src/utils/cryptography.ts +0 -141
- package/src/utils/index.ts +0 -1
- package/src/utils/publicKey.ts +0 -17
- package/tsconfig.eslint.json +0 -8
- package/tsconfig.json +0 -126
- package/tsup.config.ts +0 -58
- package/vitest.config.ts +0 -19
- package/vocs.config.ts +0 -213
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
import * as bitcoin from 'bitcoinjs-lib'
|
|
2
|
-
|
|
3
|
-
import { type BTCRpcAdapter } from '@chain-adapters/Bitcoin/BTCRpcAdapter'
|
|
4
|
-
import type {
|
|
5
|
-
BTCInput,
|
|
6
|
-
BTCNetworkIds,
|
|
7
|
-
BTCOutput,
|
|
8
|
-
BTCTransactionRequest,
|
|
9
|
-
BTCUnsignedTransaction,
|
|
10
|
-
} from '@chain-adapters/Bitcoin/types'
|
|
11
|
-
import { parseBTCNetwork } from '@chain-adapters/Bitcoin/utils'
|
|
12
|
-
import { ChainAdapter } from '@chain-adapters/ChainAdapter'
|
|
13
|
-
import type { BaseChainSignatureContract } from '@contracts/ChainSignatureContract'
|
|
14
|
-
import type { HashToSign, RSVSignature, KeyDerivationPath } from '@types'
|
|
15
|
-
import { cryptography } from '@utils'
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Implementation of the ChainAdapter interface for Bitcoin network.
|
|
19
|
-
* Handles interactions with both Bitcoin mainnet and testnet, supporting P2WPKH transactions.
|
|
20
|
-
*/
|
|
21
|
-
export class Bitcoin extends ChainAdapter<
|
|
22
|
-
BTCTransactionRequest,
|
|
23
|
-
BTCUnsignedTransaction
|
|
24
|
-
> {
|
|
25
|
-
private static readonly SATOSHIS_PER_BTC = 100_000_000
|
|
26
|
-
|
|
27
|
-
private readonly network: BTCNetworkIds
|
|
28
|
-
private readonly btcRpcAdapter: BTCRpcAdapter
|
|
29
|
-
private readonly contract: BaseChainSignatureContract
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Creates a new Bitcoin chain instance
|
|
33
|
-
* @param params - Configuration parameters
|
|
34
|
-
* @param params.network - Network identifier (mainnet/testnet)
|
|
35
|
-
* @param params.contract - Instance of the chain signature contract for MPC operations
|
|
36
|
-
* @param params.btcRpcAdapter - Bitcoin RPC adapter for network interactions
|
|
37
|
-
*/
|
|
38
|
-
constructor({
|
|
39
|
-
network,
|
|
40
|
-
contract,
|
|
41
|
-
btcRpcAdapter,
|
|
42
|
-
}: {
|
|
43
|
-
network: BTCNetworkIds
|
|
44
|
-
contract: BaseChainSignatureContract
|
|
45
|
-
btcRpcAdapter: BTCRpcAdapter
|
|
46
|
-
}) {
|
|
47
|
-
super()
|
|
48
|
-
|
|
49
|
-
this.network = network
|
|
50
|
-
this.btcRpcAdapter = btcRpcAdapter
|
|
51
|
-
this.contract = contract
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Converts satoshis to BTC
|
|
56
|
-
* @param satoshis - Amount in satoshis
|
|
57
|
-
* @returns Amount in BTC
|
|
58
|
-
*/
|
|
59
|
-
static toBTC(satoshis: number): number {
|
|
60
|
-
return satoshis / Bitcoin.SATOSHIS_PER_BTC
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Converts BTC to satoshis
|
|
65
|
-
* @param btc - Amount in BTC
|
|
66
|
-
* @returns Amount in satoshis (rounded)
|
|
67
|
-
*/
|
|
68
|
-
static toSatoshi(btc: number): number {
|
|
69
|
-
return Math.round(btc * Bitcoin.SATOSHIS_PER_BTC)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private async fetchTransaction(
|
|
73
|
-
transactionId: string
|
|
74
|
-
): Promise<bitcoin.Transaction> {
|
|
75
|
-
const data = await this.btcRpcAdapter.getTransaction(transactionId)
|
|
76
|
-
const tx = new bitcoin.Transaction()
|
|
77
|
-
|
|
78
|
-
data.vout.forEach((vout) => {
|
|
79
|
-
const scriptPubKey = Buffer.from(vout.scriptpubkey, 'hex')
|
|
80
|
-
tx.addOutput(scriptPubKey, Number(vout.value))
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
return tx
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private static transformRSVSignature(signature: RSVSignature): Buffer {
|
|
87
|
-
const r = signature.r.padStart(64, '0')
|
|
88
|
-
const s = signature.s.padStart(64, '0')
|
|
89
|
-
|
|
90
|
-
const rawSignature = Buffer.from(r + s, 'hex')
|
|
91
|
-
|
|
92
|
-
if (rawSignature.length !== 64) {
|
|
93
|
-
throw new Error('Invalid signature length.')
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return rawSignature
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Creates a Partially Signed Bitcoin Transaction (PSBT)
|
|
101
|
-
* @param params - Parameters for creating the PSBT
|
|
102
|
-
* @param params.transactionRequest - Transaction request containing inputs and outputs
|
|
103
|
-
* @returns Created PSBT instance
|
|
104
|
-
*/
|
|
105
|
-
async createPSBT({
|
|
106
|
-
transactionRequest,
|
|
107
|
-
}: {
|
|
108
|
-
transactionRequest: BTCTransactionRequest
|
|
109
|
-
}): Promise<bitcoin.Psbt> {
|
|
110
|
-
const { inputs, outputs } =
|
|
111
|
-
transactionRequest.inputs && transactionRequest.outputs
|
|
112
|
-
? transactionRequest
|
|
113
|
-
: await this.btcRpcAdapter.selectUTXOs(transactionRequest.from, [
|
|
114
|
-
{
|
|
115
|
-
address: transactionRequest.to,
|
|
116
|
-
value: parseFloat(transactionRequest.value),
|
|
117
|
-
},
|
|
118
|
-
])
|
|
119
|
-
|
|
120
|
-
const psbt = new bitcoin.Psbt({ network: parseBTCNetwork(this.network) })
|
|
121
|
-
|
|
122
|
-
await Promise.all(
|
|
123
|
-
inputs.map(async (input: BTCInput) => {
|
|
124
|
-
if (!input.scriptPubKey) {
|
|
125
|
-
const transaction = await this.fetchTransaction(input.txid)
|
|
126
|
-
const prevOut = transaction.outs[input.vout]
|
|
127
|
-
input.scriptPubKey = prevOut.script
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Prepare the input as P2WPKH
|
|
131
|
-
psbt.addInput({
|
|
132
|
-
hash: input.txid,
|
|
133
|
-
index: input.vout,
|
|
134
|
-
witnessUtxo: {
|
|
135
|
-
script: input.scriptPubKey,
|
|
136
|
-
value: input.value,
|
|
137
|
-
},
|
|
138
|
-
})
|
|
139
|
-
})
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
outputs.forEach((out: BTCOutput) => {
|
|
143
|
-
if ('address' in out) {
|
|
144
|
-
psbt.addOutput({
|
|
145
|
-
address: out.address,
|
|
146
|
-
value: out.value,
|
|
147
|
-
})
|
|
148
|
-
} else if ('script' in out) {
|
|
149
|
-
psbt.addOutput({
|
|
150
|
-
script: out.script,
|
|
151
|
-
value: out.value,
|
|
152
|
-
})
|
|
153
|
-
} else if (transactionRequest.from !== undefined) {
|
|
154
|
-
// Include change address from coinselect
|
|
155
|
-
psbt.addOutput({
|
|
156
|
-
value: Number(out.value),
|
|
157
|
-
address: transactionRequest.from,
|
|
158
|
-
})
|
|
159
|
-
}
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
return psbt
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
async getBalance(
|
|
166
|
-
address: string
|
|
167
|
-
): Promise<{ balance: bigint; decimals: number }> {
|
|
168
|
-
const balance = BigInt(await this.btcRpcAdapter.getBalance(address))
|
|
169
|
-
return {
|
|
170
|
-
balance,
|
|
171
|
-
decimals: 8,
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async deriveAddressAndPublicKey(
|
|
176
|
-
predecessor: string,
|
|
177
|
-
path: KeyDerivationPath
|
|
178
|
-
): Promise<{ address: string; publicKey: string }> {
|
|
179
|
-
const uncompressedPubKey = await this.contract.getDerivedPublicKey({
|
|
180
|
-
path,
|
|
181
|
-
predecessor,
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
if (!uncompressedPubKey) {
|
|
185
|
-
throw new Error('Failed to get derived public key')
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const derivedKey = cryptography.compressPubKey(uncompressedPubKey)
|
|
189
|
-
const publicKeyBuffer = Buffer.from(derivedKey, 'hex')
|
|
190
|
-
const network = parseBTCNetwork(this.network)
|
|
191
|
-
|
|
192
|
-
const payment = bitcoin.payments.p2wpkh({
|
|
193
|
-
pubkey: publicKeyBuffer,
|
|
194
|
-
network,
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
const { address } = payment
|
|
198
|
-
|
|
199
|
-
if (!address) {
|
|
200
|
-
throw new Error('Failed to generate Bitcoin address')
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return { address, publicKey: derivedKey }
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
serializeTransaction(transaction: BTCUnsignedTransaction): string {
|
|
207
|
-
return JSON.stringify({
|
|
208
|
-
psbt: transaction.psbt.toHex(),
|
|
209
|
-
publicKey: transaction.publicKey,
|
|
210
|
-
})
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
deserializeTransaction(serialized: string): BTCUnsignedTransaction {
|
|
214
|
-
const transactionJSON = JSON.parse(serialized)
|
|
215
|
-
return {
|
|
216
|
-
psbt: bitcoin.Psbt.fromHex(transactionJSON.psbt as string),
|
|
217
|
-
publicKey: transactionJSON.publicKey,
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
async prepareTransactionForSigning(
|
|
222
|
-
transactionRequest: BTCTransactionRequest
|
|
223
|
-
): Promise<{
|
|
224
|
-
transaction: BTCUnsignedTransaction
|
|
225
|
-
hashesToSign: HashToSign[]
|
|
226
|
-
}> {
|
|
227
|
-
const publicKeyBuffer = Buffer.from(transactionRequest.publicKey, 'hex')
|
|
228
|
-
const psbt = await this.createPSBT({
|
|
229
|
-
transactionRequest,
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
// We can't double sign a PSBT, therefore we serialize the payload before to return it
|
|
233
|
-
const psbtHex = psbt.toHex()
|
|
234
|
-
|
|
235
|
-
const hashesToSign: HashToSign[] = []
|
|
236
|
-
|
|
237
|
-
const mockKeyPair = (index: number): bitcoin.Signer => ({
|
|
238
|
-
publicKey: publicKeyBuffer,
|
|
239
|
-
sign: (hash: Buffer): Buffer => {
|
|
240
|
-
hashesToSign[index] = Array.from(hash)
|
|
241
|
-
// Return dummy signature to satisfy the interface
|
|
242
|
-
return Buffer.alloc(64)
|
|
243
|
-
},
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
for (let index = 0; index < psbt.inputCount; index++) {
|
|
247
|
-
psbt.signInput(index, mockKeyPair(index))
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
transaction: {
|
|
252
|
-
psbt: bitcoin.Psbt.fromHex(psbtHex),
|
|
253
|
-
publicKey: transactionRequest.publicKey,
|
|
254
|
-
},
|
|
255
|
-
hashesToSign,
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
finalizeTransactionSigning({
|
|
260
|
-
transaction: { psbt, publicKey },
|
|
261
|
-
rsvSignatures,
|
|
262
|
-
}: {
|
|
263
|
-
transaction: BTCUnsignedTransaction
|
|
264
|
-
rsvSignatures: RSVSignature[]
|
|
265
|
-
}): string {
|
|
266
|
-
const publicKeyBuffer = Buffer.from(publicKey, 'hex')
|
|
267
|
-
|
|
268
|
-
const keyPair = (index: number): bitcoin.Signer => ({
|
|
269
|
-
publicKey: publicKeyBuffer,
|
|
270
|
-
sign: () => {
|
|
271
|
-
const mpcSignature = rsvSignatures[index]
|
|
272
|
-
return Bitcoin.transformRSVSignature(mpcSignature)
|
|
273
|
-
},
|
|
274
|
-
})
|
|
275
|
-
|
|
276
|
-
for (let index = 0; index < psbt.inputCount; index++) {
|
|
277
|
-
psbt.signInput(index, keyPair(index))
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
psbt.finalizeAllInputs()
|
|
281
|
-
return psbt.extractTransaction().toHex()
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
async broadcastTx(txSerialized: string): Promise<string> {
|
|
285
|
-
return await this.btcRpcAdapter.broadcastTransaction(txSerialized)
|
|
286
|
-
}
|
|
287
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Bitcoin
|
|
2
|
-
export { Bitcoin } from './Bitcoin'
|
|
3
|
-
|
|
4
|
-
export { BTCRpcAdapters, BTCRpcAdapter } from './BTCRpcAdapter'
|
|
5
|
-
|
|
6
|
-
export type {
|
|
7
|
-
BTCTransactionRequest,
|
|
8
|
-
BTCUnsignedTransaction,
|
|
9
|
-
BTCTransaction,
|
|
10
|
-
BTCOutput,
|
|
11
|
-
BTCInput,
|
|
12
|
-
BTCNetworkIds,
|
|
13
|
-
} from './types'
|
|
@@ -1,48 +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
|
-
| {
|
|
19
|
-
value: number
|
|
20
|
-
}
|
|
21
|
-
| { address: string; value: number }
|
|
22
|
-
| { script: Buffer; value: number }
|
|
23
|
-
|
|
24
|
-
export type BTCTransactionRequest = {
|
|
25
|
-
publicKey: string
|
|
26
|
-
} & (
|
|
27
|
-
| {
|
|
28
|
-
inputs: BTCInput[]
|
|
29
|
-
outputs: BTCOutput[]
|
|
30
|
-
from?: never
|
|
31
|
-
to?: never
|
|
32
|
-
value?: never
|
|
33
|
-
}
|
|
34
|
-
| {
|
|
35
|
-
inputs?: never
|
|
36
|
-
outputs?: never
|
|
37
|
-
from: string
|
|
38
|
-
to: string
|
|
39
|
-
value: string
|
|
40
|
-
}
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
export interface BTCUnsignedTransaction {
|
|
44
|
-
psbt: bitcoin.Psbt
|
|
45
|
-
publicKey: string
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
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
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type { KeyDerivationPath, HashToSign, RSVSignature } from '@types'
|
|
2
|
-
|
|
3
|
-
export abstract class ChainAdapter<TransactionRequest, UnsignedTransaction> {
|
|
4
|
-
/**
|
|
5
|
-
* Gets the native token balance and decimals for a given address
|
|
6
|
-
*
|
|
7
|
-
* @param address - The address to check
|
|
8
|
-
* @returns Promise resolving to an object containing:
|
|
9
|
-
* - balance: The balance as a bigint, in the chain's base units
|
|
10
|
-
* - decimals: The number of decimals used to format the balance
|
|
11
|
-
*/
|
|
12
|
-
abstract getBalance(address: string): Promise<{
|
|
13
|
-
balance: bigint
|
|
14
|
-
decimals: number
|
|
15
|
-
}>
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Uses Sig Network Key Derivation Function to derive the address and public key. from a signer ID and string path.
|
|
19
|
-
*
|
|
20
|
-
* @param predecessor - The id/address of the account requesting signature
|
|
21
|
-
* @param path - The string path used to derive the key
|
|
22
|
-
* @returns Promise resolving to the derived address and public key
|
|
23
|
-
*/
|
|
24
|
-
abstract deriveAddressAndPublicKey(
|
|
25
|
-
predecessor: string,
|
|
26
|
-
path: KeyDerivationPath
|
|
27
|
-
): Promise<{
|
|
28
|
-
address: string
|
|
29
|
-
publicKey: string
|
|
30
|
-
}>
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Serializes an unsigned transaction to a string format.
|
|
34
|
-
* This is useful for storing or transmitting the transaction.
|
|
35
|
-
*
|
|
36
|
-
* @param transaction - The unsigned transaction to serialize
|
|
37
|
-
* @returns The serialized transaction string
|
|
38
|
-
*/
|
|
39
|
-
abstract serializeTransaction(transaction: UnsignedTransaction): string
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Deserializes a transaction string back into an unsigned transaction object.
|
|
43
|
-
* This reverses the serialization done by serializeTransaction().
|
|
44
|
-
*
|
|
45
|
-
* @param serialized - The serialized transaction string
|
|
46
|
-
* @returns The deserialized unsigned transaction
|
|
47
|
-
*/
|
|
48
|
-
abstract deserializeTransaction(serialized: string): UnsignedTransaction
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Prepares a transaction for Sig Network MPC signing by creating the necessary payloads.
|
|
52
|
-
* This method handles chain-specific transaction preparation including:
|
|
53
|
-
* - Fee calculation
|
|
54
|
-
* - Nonce/sequence management
|
|
55
|
-
* - UTXO selection (for UTXO-based chains)
|
|
56
|
-
* - Transaction encoding
|
|
57
|
-
*
|
|
58
|
-
* @param transactionRequest - The transaction request containing parameters like recipient, amount, etc.
|
|
59
|
-
* @returns Promise resolving to an object containing:
|
|
60
|
-
* - transaction: The unsigned transaction
|
|
61
|
-
* - hashesToSign: Array of payloads to be signed by MPC. The order of these payloads must match
|
|
62
|
-
* the order of signatures provided to finalizeTransactionSigning()
|
|
63
|
-
*/
|
|
64
|
-
abstract prepareTransactionForSigning(
|
|
65
|
-
transactionRequest: TransactionRequest
|
|
66
|
-
): Promise<{
|
|
67
|
-
transaction: UnsignedTransaction
|
|
68
|
-
hashesToSign: HashToSign[]
|
|
69
|
-
}>
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Adds Sig Network MPC-generated signatures to an unsigned transaction.
|
|
73
|
-
*
|
|
74
|
-
* @param params - Parameters for adding signatures
|
|
75
|
-
* @param params.transaction - The unsigned transaction to add signatures to
|
|
76
|
-
* @param params.rsvSignatures - Array of RSV signatures generated through MPC. Must be in the same order
|
|
77
|
-
* as the payloads returned by prepareTransactionForSigning()
|
|
78
|
-
* @returns The serialized signed transaction ready for broadcast
|
|
79
|
-
*/
|
|
80
|
-
abstract finalizeTransactionSigning(params: {
|
|
81
|
-
transaction: UnsignedTransaction
|
|
82
|
-
rsvSignatures: RSVSignature[]
|
|
83
|
-
}): string
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Broadcasts a signed transaction to the network.
|
|
87
|
-
*
|
|
88
|
-
* @param txSerialized - The serialized signed transaction
|
|
89
|
-
* @returns Promise resolving to the transaction hash/ID
|
|
90
|
-
*/
|
|
91
|
-
abstract broadcastTx(txSerialized: string): Promise<string>
|
|
92
|
-
}
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import { encodeSecp256k1Pubkey } from '@cosmjs/amino'
|
|
2
|
-
import { ripemd160, sha256 } from '@cosmjs/crypto'
|
|
3
|
-
import { toBase64, fromBase64, fromHex } from '@cosmjs/encoding'
|
|
4
|
-
import {
|
|
5
|
-
Registry,
|
|
6
|
-
makeSignBytes,
|
|
7
|
-
encodePubkey,
|
|
8
|
-
makeAuthInfoBytes,
|
|
9
|
-
makeSignDoc,
|
|
10
|
-
type TxBodyEncodeObject,
|
|
11
|
-
} from '@cosmjs/proto-signing'
|
|
12
|
-
import { GasPrice, StargateClient, calculateFee } from '@cosmjs/stargate'
|
|
13
|
-
import { bech32 } from 'bech32'
|
|
14
|
-
import { SignMode } from 'cosmjs-types/cosmos/tx/signing/v1beta1/signing'
|
|
15
|
-
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx'
|
|
16
|
-
|
|
17
|
-
import { ChainAdapter } from '@chain-adapters/ChainAdapter'
|
|
18
|
-
import type {
|
|
19
|
-
CosmosNetworkIds,
|
|
20
|
-
CosmosTransactionRequest,
|
|
21
|
-
CosmosUnsignedTransaction,
|
|
22
|
-
ChainInfo,
|
|
23
|
-
BalanceResponse,
|
|
24
|
-
} from '@chain-adapters/Cosmos/types'
|
|
25
|
-
import { fetchChainInfo } from '@chain-adapters/Cosmos/utils'
|
|
26
|
-
import type { BaseChainSignatureContract } from '@contracts/ChainSignatureContract'
|
|
27
|
-
import type { HashToSign, RSVSignature, KeyDerivationPath } from '@types'
|
|
28
|
-
import { cryptography } from '@utils'
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Implementation of the ChainAdapter interface for Cosmos-based networks.
|
|
32
|
-
* Handles interactions with Cosmos SDK chains like Cosmos Hub, Osmosis, etc.
|
|
33
|
-
*/
|
|
34
|
-
export class Cosmos extends ChainAdapter<
|
|
35
|
-
CosmosTransactionRequest,
|
|
36
|
-
CosmosUnsignedTransaction
|
|
37
|
-
> {
|
|
38
|
-
private readonly registry: Registry
|
|
39
|
-
private readonly chainId: CosmosNetworkIds
|
|
40
|
-
private readonly contract: BaseChainSignatureContract
|
|
41
|
-
private readonly endpoints?: {
|
|
42
|
-
rpcUrl?: string
|
|
43
|
-
restUrl?: string
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Creates a new Cosmos chain instance
|
|
48
|
-
* @param params - Configuration parameters
|
|
49
|
-
* @param params.chainId - Chain id for the Cosmos network
|
|
50
|
-
* @param params.contract - Instance of the chain signature contract for MPC operations
|
|
51
|
-
* @param params.endpoints - Optional RPC and REST endpoints
|
|
52
|
-
* @param params.endpoints.rpcUrl - Optional RPC endpoint URL
|
|
53
|
-
* @param params.endpoints.restUrl - Optional REST endpoint URL
|
|
54
|
-
*/
|
|
55
|
-
constructor({
|
|
56
|
-
chainId,
|
|
57
|
-
contract,
|
|
58
|
-
endpoints,
|
|
59
|
-
}: {
|
|
60
|
-
contract: BaseChainSignatureContract
|
|
61
|
-
chainId: CosmosNetworkIds
|
|
62
|
-
endpoints?: {
|
|
63
|
-
rpcUrl?: string
|
|
64
|
-
restUrl?: string
|
|
65
|
-
}
|
|
66
|
-
}) {
|
|
67
|
-
super()
|
|
68
|
-
|
|
69
|
-
this.contract = contract
|
|
70
|
-
this.registry = new Registry()
|
|
71
|
-
this.chainId = chainId
|
|
72
|
-
this.endpoints = endpoints
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private transformRSVSignature(rsvSignature: RSVSignature): Uint8Array {
|
|
76
|
-
return new Uint8Array([
|
|
77
|
-
...fromHex(rsvSignature.r),
|
|
78
|
-
...fromHex(rsvSignature.s),
|
|
79
|
-
])
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private async getChainInfo(): Promise<ChainInfo> {
|
|
83
|
-
return {
|
|
84
|
-
...(await fetchChainInfo(this.chainId)),
|
|
85
|
-
...this.endpoints,
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async getBalance(
|
|
90
|
-
address: string
|
|
91
|
-
): Promise<{ balance: bigint; decimals: number }> {
|
|
92
|
-
try {
|
|
93
|
-
const { restUrl, denom, decimals } = await this.getChainInfo()
|
|
94
|
-
|
|
95
|
-
const response = await fetch(
|
|
96
|
-
`${restUrl}/cosmos/bank/v1beta1/balances/${address}`
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
if (!response.ok) {
|
|
100
|
-
throw new Error(`HTTP error! status: ${response.status}`)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const data = (await response.json()) as BalanceResponse
|
|
104
|
-
const balance = data.balances.find((b) => b.denom === denom)
|
|
105
|
-
const amount = balance?.amount ?? '0'
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
balance: BigInt(amount),
|
|
109
|
-
decimals,
|
|
110
|
-
}
|
|
111
|
-
} catch (error) {
|
|
112
|
-
console.error('Failed to fetch Cosmos balance:', error)
|
|
113
|
-
throw new Error('Failed to fetch Cosmos balance')
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async deriveAddressAndPublicKey(
|
|
118
|
-
predecessor: string,
|
|
119
|
-
path: KeyDerivationPath
|
|
120
|
-
): Promise<{
|
|
121
|
-
address: string
|
|
122
|
-
publicKey: string
|
|
123
|
-
}> {
|
|
124
|
-
const { prefix } = await this.getChainInfo()
|
|
125
|
-
const uncompressedPubKey = await this.contract.getDerivedPublicKey({
|
|
126
|
-
path,
|
|
127
|
-
predecessor,
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
if (!uncompressedPubKey) {
|
|
131
|
-
throw new Error('Failed to get derived public key')
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const derivedKey = cryptography.compressPubKey(uncompressedPubKey)
|
|
135
|
-
const pubKeySha256 = sha256(fromHex(derivedKey))
|
|
136
|
-
const ripemd160Hash = ripemd160(pubKeySha256)
|
|
137
|
-
const address = bech32.encode(prefix, bech32.toWords(ripemd160Hash))
|
|
138
|
-
|
|
139
|
-
return { address, publicKey: derivedKey }
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
serializeTransaction(transaction: CosmosUnsignedTransaction): string {
|
|
143
|
-
const serialized = TxRaw.encode(transaction).finish()
|
|
144
|
-
return toBase64(serialized)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
deserializeTransaction(serialized: string): CosmosUnsignedTransaction {
|
|
148
|
-
return TxRaw.decode(fromBase64(serialized))
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async prepareTransactionForSigning(
|
|
152
|
-
transactionRequest: CosmosTransactionRequest
|
|
153
|
-
): Promise<{
|
|
154
|
-
transaction: CosmosUnsignedTransaction
|
|
155
|
-
hashesToSign: HashToSign[]
|
|
156
|
-
}> {
|
|
157
|
-
const { denom, rpcUrl, gasPrice } = await this.getChainInfo()
|
|
158
|
-
const publicKeyBytes = fromHex(transactionRequest.publicKey)
|
|
159
|
-
|
|
160
|
-
const gasLimit = transactionRequest.gas || 200_000
|
|
161
|
-
|
|
162
|
-
const fee = calculateFee(
|
|
163
|
-
gasLimit,
|
|
164
|
-
GasPrice.fromString(`${gasPrice}${denom}`)
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
const client = await StargateClient.connect(rpcUrl)
|
|
168
|
-
const accountOnChain = await client.getAccount(transactionRequest.address)
|
|
169
|
-
if (!accountOnChain) {
|
|
170
|
-
throw new Error(
|
|
171
|
-
`Account ${transactionRequest.address} does not exist on chain`
|
|
172
|
-
)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const { accountNumber, sequence } = accountOnChain
|
|
176
|
-
|
|
177
|
-
const txBodyEncodeObject: TxBodyEncodeObject = {
|
|
178
|
-
typeUrl: '/cosmos.tx.v1beta1.TxBody',
|
|
179
|
-
value: {
|
|
180
|
-
messages: transactionRequest.messages,
|
|
181
|
-
memo: transactionRequest.memo || '',
|
|
182
|
-
},
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const txBodyBytes = this.registry.encode(txBodyEncodeObject)
|
|
186
|
-
|
|
187
|
-
const pubkey = encodePubkey(encodeSecp256k1Pubkey(publicKeyBytes))
|
|
188
|
-
|
|
189
|
-
// TODO: Allow caller to provide: multiple signers, fee payer, fee granter
|
|
190
|
-
const authInfoBytes = makeAuthInfoBytes(
|
|
191
|
-
[
|
|
192
|
-
{
|
|
193
|
-
pubkey,
|
|
194
|
-
sequence,
|
|
195
|
-
},
|
|
196
|
-
],
|
|
197
|
-
fee.amount,
|
|
198
|
-
Number(fee.gas),
|
|
199
|
-
undefined,
|
|
200
|
-
undefined,
|
|
201
|
-
SignMode.SIGN_MODE_DIRECT
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
const signDoc = makeSignDoc(
|
|
205
|
-
txBodyBytes,
|
|
206
|
-
authInfoBytes,
|
|
207
|
-
this.chainId,
|
|
208
|
-
accountNumber
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
const signBytes = makeSignBytes(signDoc)
|
|
212
|
-
const payload = Array.from(sha256(signBytes))
|
|
213
|
-
|
|
214
|
-
return {
|
|
215
|
-
transaction: TxRaw.fromPartial({
|
|
216
|
-
bodyBytes: txBodyBytes,
|
|
217
|
-
authInfoBytes,
|
|
218
|
-
signatures: [],
|
|
219
|
-
}),
|
|
220
|
-
hashesToSign: [payload],
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
finalizeTransactionSigning({
|
|
225
|
-
transaction,
|
|
226
|
-
rsvSignatures,
|
|
227
|
-
}: {
|
|
228
|
-
transaction: CosmosUnsignedTransaction
|
|
229
|
-
rsvSignatures: RSVSignature[]
|
|
230
|
-
}): string {
|
|
231
|
-
// Allow support for multi-sig but the package only supports single-sig
|
|
232
|
-
transaction.signatures = rsvSignatures.map((sig) =>
|
|
233
|
-
this.transformRSVSignature(sig)
|
|
234
|
-
)
|
|
235
|
-
|
|
236
|
-
const txBytes = TxRaw.encode(transaction).finish()
|
|
237
|
-
return Buffer.from(txBytes).toString('hex')
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
async broadcastTx(txSerialized: string): Promise<string> {
|
|
241
|
-
try {
|
|
242
|
-
const { rpcUrl } = await this.getChainInfo()
|
|
243
|
-
const client = await StargateClient.connect(rpcUrl)
|
|
244
|
-
|
|
245
|
-
const txBytes = fromHex(txSerialized)
|
|
246
|
-
const broadcastResponse = await client.broadcastTx(txBytes)
|
|
247
|
-
|
|
248
|
-
if (broadcastResponse.code !== 0) {
|
|
249
|
-
throw new Error(`Broadcast error: ${broadcastResponse.rawLog}`)
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return broadcastResponse.transactionHash
|
|
253
|
-
} catch (error) {
|
|
254
|
-
console.error('Transaction broadcast failed:', error)
|
|
255
|
-
throw new Error('Failed to broadcast transaction.')
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|