@meshconnect/uwc-bitcoin 0.2.4-snapshot.ec6b95b → 0.3.0
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/dist/adapters/okx.d.ts +60 -0
- package/dist/adapters/okx.d.ts.map +1 -0
- package/dist/adapters/okx.js +93 -0
- package/dist/adapters/okx.js.map +1 -0
- package/dist/adapters/wallet-standard.d.ts +10 -1
- package/dist/adapters/wallet-standard.d.ts.map +1 -1
- package/dist/adapters/wallet-standard.js +19 -2
- package/dist/adapters/wallet-standard.js.map +1 -1
- package/dist/bitcoin-namespace.d.ts +7 -2
- package/dist/bitcoin-namespace.d.ts.map +1 -1
- package/dist/bitcoin-namespace.js +14 -2
- package/dist/bitcoin-namespace.js.map +1 -1
- package/dist/encoding.d.ts +1 -0
- package/dist/encoding.d.ts.map +1 -1
- package/dist/encoding.js +17 -0
- package/dist/encoding.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/adapters/okx.test.ts +176 -0
- package/src/adapters/okx.ts +155 -0
- package/src/adapters/wallet-standard.ts +24 -2
- package/src/bitcoin-namespace.test.ts +59 -0
- package/src/bitcoin-namespace.ts +14 -2
- package/src/encoding.ts +18 -0
- package/src/index.ts +3 -2
- package/dist/adapters/walletconnect.d.ts +0 -36
- package/dist/adapters/walletconnect.d.ts.map +0 -1
- package/dist/adapters/walletconnect.js +0 -90
- package/dist/adapters/walletconnect.js.map +0 -1
- package/src/adapters/walletconnect.test.ts +0 -97
- package/src/adapters/walletconnect.ts +0 -126
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BitcoinAccount,
|
|
3
|
-
BitcoinPsbtSignRequest,
|
|
4
|
-
BitcoinSendTransferRequest,
|
|
5
|
-
BitcoinSigHash,
|
|
6
|
-
BitcoinSignMessageParams,
|
|
7
|
-
SignatureType,
|
|
8
|
-
TransactionResult
|
|
9
|
-
} from '@meshconnect/uwc-types'
|
|
10
|
-
import { WalletConnectorError } from '@meshconnect/uwc-types'
|
|
11
|
-
import type { BitcoinTransportAdapter } from '../adapter'
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Issues a WalletConnect JSON-RPC request for a bip122 method. The WalletConnect
|
|
15
|
-
* transport binds this to its live `SignClient` + session topic + chainId, e.g.
|
|
16
|
-
* `(method, params) => signClient.request({ topic, chainId, request: { method, params } })`.
|
|
17
|
-
* Kept as a plain function so `uwc-bitcoin` needs no `@walletconnect/*` dependency.
|
|
18
|
-
*/
|
|
19
|
-
export type BitcoinWalletConnectRequest = (
|
|
20
|
-
method: string,
|
|
21
|
-
params: Record<string, unknown>
|
|
22
|
-
) => Promise<unknown>
|
|
23
|
-
|
|
24
|
-
/** Maps a SIGHASH flag to its numeric value (Bitcoin Core encoding). */
|
|
25
|
-
const SIGHASH_VALUES: Record<BitcoinSigHash, number> = {
|
|
26
|
-
ALL: 0x01,
|
|
27
|
-
NONE: 0x02,
|
|
28
|
-
SINGLE: 0x03,
|
|
29
|
-
'ALL|ANYONECANPAY': 0x81,
|
|
30
|
-
'NONE|ANYONECANPAY': 0x82,
|
|
31
|
-
'SINGLE|ANYONECANPAY': 0x83
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface WcAccountAddress {
|
|
35
|
-
address: string
|
|
36
|
-
publicKey?: string
|
|
37
|
-
path?: string
|
|
38
|
-
intention?: string
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* WalletConnect (bip122) transport adapter — the Path A / mobile path (Trust
|
|
43
|
-
* Wallet, …). The WalletConnect transport pairs the session and constructs this
|
|
44
|
-
* adapter bound to the connected account's first external address plus a
|
|
45
|
-
* `request` function; this adapter maps our domain shapes onto the Reown/CAIP-2
|
|
46
|
-
* bip122 JSON-RPC methods (`getAccountAddresses`, `signMessage`, `signPsbt`,
|
|
47
|
-
* `sendTransfer`).
|
|
48
|
-
*
|
|
49
|
-
* Wire format follows the Reown Bitcoin RPC reference (what wallets implement
|
|
50
|
-
* over WalletConnect) — all-JSON strings, `account` on every request. NOTE:
|
|
51
|
-
* untested end-to-end; grounded on the spec, not a live wallet.
|
|
52
|
-
*/
|
|
53
|
-
export class WalletConnectBitcoinAdapter implements BitcoinTransportAdapter {
|
|
54
|
-
/**
|
|
55
|
-
* @param account The connected account's first external address — the
|
|
56
|
-
* `account` parameter every bip122 method requires.
|
|
57
|
-
* @param request Issues the bound WalletConnect JSON-RPC request.
|
|
58
|
-
*/
|
|
59
|
-
constructor(
|
|
60
|
-
private readonly account: string,
|
|
61
|
-
private readonly request: BitcoinWalletConnectRequest
|
|
62
|
-
) {}
|
|
63
|
-
|
|
64
|
-
async getAccounts(): Promise<BitcoinAccount[]> {
|
|
65
|
-
const result = (await this.request('getAccountAddresses', {
|
|
66
|
-
account: this.account
|
|
67
|
-
})) as WcAccountAddress[]
|
|
68
|
-
return result.map(entry => ({
|
|
69
|
-
address: entry.address,
|
|
70
|
-
// WalletConnect wallets MAY omit the public key; empty when absent.
|
|
71
|
-
publicKey: entry.publicKey ?? '',
|
|
72
|
-
...(entry.intention === 'ordinal'
|
|
73
|
-
? { purpose: 'ordinals' as const }
|
|
74
|
-
: entry.intention === 'payment'
|
|
75
|
-
? { purpose: 'payment' as const }
|
|
76
|
-
: {})
|
|
77
|
-
}))
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async signMessage(params: BitcoinSignMessageParams): Promise<SignatureType> {
|
|
81
|
-
const result = (await this.request('signMessage', {
|
|
82
|
-
account: this.account,
|
|
83
|
-
message: params.message,
|
|
84
|
-
address: params.account.address,
|
|
85
|
-
...(params.protocol ? { protocol: params.protocol } : {})
|
|
86
|
-
})) as { signature: string }
|
|
87
|
-
return { type: 'standard', signature: result.signature }
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async signPsbt(request: BitcoinPsbtSignRequest): Promise<string> {
|
|
91
|
-
if (!request.inputsToSign?.length) {
|
|
92
|
-
throw new WalletConnectorError({
|
|
93
|
-
type: 'unknown',
|
|
94
|
-
message:
|
|
95
|
-
'walletconnect bitcoin: signPsbt requires inputsToSign (the WC signPsbt method has no "sign all" mode)'
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
const signInputs = request.inputsToSign.flatMap(input =>
|
|
99
|
-
input.signingIndexes.map(index => ({
|
|
100
|
-
address: input.address,
|
|
101
|
-
index,
|
|
102
|
-
...(input.sigHash
|
|
103
|
-
? { sighashTypes: [SIGHASH_VALUES[input.sigHash]] }
|
|
104
|
-
: {})
|
|
105
|
-
}))
|
|
106
|
-
)
|
|
107
|
-
const result = (await this.request('signPsbt', {
|
|
108
|
-
account: this.account,
|
|
109
|
-
psbt: request.psbt,
|
|
110
|
-
signInputs,
|
|
111
|
-
broadcast: false
|
|
112
|
-
})) as { psbt: string }
|
|
113
|
-
return result.psbt
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async sendTransfer(
|
|
117
|
-
request: BitcoinSendTransferRequest
|
|
118
|
-
): Promise<TransactionResult> {
|
|
119
|
-
const result = (await this.request('sendTransfer', {
|
|
120
|
-
account: this.account,
|
|
121
|
-
recipientAddress: request.to,
|
|
122
|
-
amount: request.amount.toString()
|
|
123
|
-
})) as { txid: string }
|
|
124
|
-
return result.txid
|
|
125
|
-
}
|
|
126
|
-
}
|