@meshconnect/uwc-bitcoin 0.2.2 → 0.2.3
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/adapter.d.ts +25 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +2 -0
- package/dist/adapter.js.map +1 -0
- package/dist/bitcoin-namespace.d.ts +17 -9
- package/dist/bitcoin-namespace.d.ts.map +1 -1
- package/dist/bitcoin-namespace.js +23 -8
- package/dist/bitcoin-namespace.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/adapter.ts +31 -0
- package/src/bitcoin-namespace.test.ts +59 -5
- package/src/bitcoin-namespace.ts +32 -9
- package/src/index.ts +1 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BitcoinAccount, BitcoinSignMessageParams, SignatureType } from '@meshconnect/uwc-types';
|
|
2
|
+
/**
|
|
3
|
+
* The seam between the Bitcoin namespace module and a single transport.
|
|
4
|
+
*
|
|
5
|
+
* A concrete adapter (Phase 3) is constructed by its transport bound to an
|
|
6
|
+
* already-connected provider/session — Wallet Standard `bitcoin:*` for the
|
|
7
|
+
* injected transport, WalletConnect bip122 for the WalletConnect transport —
|
|
8
|
+
* so the port carries no `connect`/provider argument: connecting is the
|
|
9
|
+
* transport's job. Each adapter converts between these transport-agnostic
|
|
10
|
+
* domain shapes and its wallet's native interface (e.g. hex ↔ `Uint8Array`).
|
|
11
|
+
*
|
|
12
|
+
* Phase 2 locks the grounded verify-flow methods. `signPsbt` (Path B, returns a
|
|
13
|
+
* signed PSBT the module then finalizes + broadcasts) and `sendTransfer`
|
|
14
|
+
* (Path A) are added alongside their concrete adapters in Phase 3 rather than
|
|
15
|
+
* guessed here.
|
|
16
|
+
*/
|
|
17
|
+
export interface BitcoinTransportAdapter {
|
|
18
|
+
/** Enumerate the bip122 accounts available on the connected session. */
|
|
19
|
+
getAccounts(): Promise<BitcoinAccount[]>;
|
|
20
|
+
/** Sign a message with the given account. */
|
|
21
|
+
signMessage(params: BitcoinSignMessageParams): Promise<SignatureType>;
|
|
22
|
+
/** Release any session resources the adapter holds. Optional. */
|
|
23
|
+
disconnect?(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,wBAAwB,EACxB,aAAa,EACd,MAAM,wBAAwB,CAAA;AAE/B;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,uBAAuB;IACtC,wEAAwE;IACxE,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAA;IAExC,6CAA6C;IAC7C,WAAW,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;IAErE,iEAAiE;IACjE,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Namespace, Network } from '@meshconnect/uwc-types';
|
|
1
|
+
import type { BitcoinAccount, BitcoinSignMessageParams, Namespace, Network, SignatureType } from '@meshconnect/uwc-types';
|
|
2
|
+
import type { BitcoinTransportAdapter } from './adapter';
|
|
2
3
|
/** CAIP-2 namespace this module serves. */
|
|
3
4
|
export declare const BITCOIN_NAMESPACE: Namespace;
|
|
4
5
|
/**
|
|
@@ -14,23 +15,30 @@ export declare function assertBitcoinNetwork(network: Network, method: string):
|
|
|
14
15
|
* (`injected-connector`, `wallet-connect-connector`) own wallet discovery,
|
|
15
16
|
* pairing, and the provider/session lifecycle. This module owns only
|
|
16
17
|
* Bitcoin-specific operations performed against a transport-supplied
|
|
17
|
-
* provider/session
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* provider/session, delegating each to the {@link BitcoinTransportAdapter} it
|
|
19
|
+
* was constructed with — the transport builds that adapter bound to the live
|
|
20
|
+
* session.
|
|
20
21
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* Phase 1 (scaffold): namespace identity + the shared network guard only.
|
|
22
|
+
* Phase 2 exposes the grounded verify-flow operations (account enumeration and
|
|
23
|
+
* message signing). PSBT signing (Path B) plus finalize/broadcast, and the
|
|
24
|
+
* high-level `sendTransfer` (Path A), land in Phase 3 alongside their concrete
|
|
25
|
+
* adapters.
|
|
26
26
|
*
|
|
27
27
|
* Phased build plan:
|
|
28
28
|
* https://app.notion.com/p/3a5f862e950a8187b3d3f0e255d13f45
|
|
29
29
|
*/
|
|
30
30
|
export declare class BitcoinNamespace {
|
|
31
|
+
private readonly adapter;
|
|
31
32
|
/** CAIP-2 namespace this module serves. */
|
|
32
33
|
readonly namespace: Namespace;
|
|
34
|
+
constructor(adapter: BitcoinTransportAdapter);
|
|
33
35
|
/** Throws unless `network` is a bip122 network. */
|
|
34
36
|
assertSupportedNetwork(network: Network): void;
|
|
37
|
+
/** Enumerate the bip122 accounts on the connected session. */
|
|
38
|
+
getAccounts(): Promise<BitcoinAccount[]>;
|
|
39
|
+
/** Sign a message with the given account. */
|
|
40
|
+
signMessage(params: BitcoinSignMessageParams): Promise<SignatureType>;
|
|
41
|
+
/** Release any session resources the adapter holds. */
|
|
42
|
+
disconnect(): Promise<void>;
|
|
35
43
|
}
|
|
36
44
|
//# sourceMappingURL=bitcoin-namespace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitcoin-namespace.d.ts","sourceRoot":"","sources":["../src/bitcoin-namespace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"bitcoin-namespace.d.ts","sourceRoot":"","sources":["../src/bitcoin-namespace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,wBAAwB,EACxB,SAAS,EACT,OAAO,EACP,aAAa,EACd,MAAM,wBAAwB,CAAA;AAE/B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAA;AAExD,2CAA2C;AAC3C,eAAO,MAAM,iBAAiB,EAAE,SAAoB,CAAA;AAEpD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAO3E;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,gBAAgB;IAIf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAHpC,2CAA2C;IAC3C,QAAQ,CAAC,SAAS,YAAoB;gBAET,OAAO,EAAE,uBAAuB;IAE7D,mDAAmD;IACnD,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAI9C,8DAA8D;IAC9D,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAIxC,6CAA6C;IAC7C,WAAW,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,aAAa,CAAC;IAIrE,uDAAuD;IACjD,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
|
|
@@ -21,25 +21,40 @@ export function assertBitcoinNetwork(network, method) {
|
|
|
21
21
|
* (`injected-connector`, `wallet-connect-connector`) own wallet discovery,
|
|
22
22
|
* pairing, and the provider/session lifecycle. This module owns only
|
|
23
23
|
* Bitcoin-specific operations performed against a transport-supplied
|
|
24
|
-
* provider/session
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* provider/session, delegating each to the {@link BitcoinTransportAdapter} it
|
|
25
|
+
* was constructed with — the transport builds that adapter bound to the live
|
|
26
|
+
* session.
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* Phase 1 (scaffold): namespace identity + the shared network guard only.
|
|
28
|
+
* Phase 2 exposes the grounded verify-flow operations (account enumeration and
|
|
29
|
+
* message signing). PSBT signing (Path B) plus finalize/broadcast, and the
|
|
30
|
+
* high-level `sendTransfer` (Path A), land in Phase 3 alongside their concrete
|
|
31
|
+
* adapters.
|
|
33
32
|
*
|
|
34
33
|
* Phased build plan:
|
|
35
34
|
* https://app.notion.com/p/3a5f862e950a8187b3d3f0e255d13f45
|
|
36
35
|
*/
|
|
37
36
|
export class BitcoinNamespace {
|
|
37
|
+
adapter;
|
|
38
38
|
/** CAIP-2 namespace this module serves. */
|
|
39
39
|
namespace = BITCOIN_NAMESPACE;
|
|
40
|
+
constructor(adapter) {
|
|
41
|
+
this.adapter = adapter;
|
|
42
|
+
}
|
|
40
43
|
/** Throws unless `network` is a bip122 network. */
|
|
41
44
|
assertSupportedNetwork(network) {
|
|
42
45
|
assertBitcoinNetwork(network, 'BitcoinNamespace.assertSupportedNetwork');
|
|
43
46
|
}
|
|
47
|
+
/** Enumerate the bip122 accounts on the connected session. */
|
|
48
|
+
getAccounts() {
|
|
49
|
+
return this.adapter.getAccounts();
|
|
50
|
+
}
|
|
51
|
+
/** Sign a message with the given account. */
|
|
52
|
+
signMessage(params) {
|
|
53
|
+
return this.adapter.signMessage(params);
|
|
54
|
+
}
|
|
55
|
+
/** Release any session resources the adapter holds. */
|
|
56
|
+
async disconnect() {
|
|
57
|
+
await this.adapter.disconnect?.();
|
|
58
|
+
}
|
|
44
59
|
}
|
|
45
60
|
//# sourceMappingURL=bitcoin-namespace.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitcoin-namespace.js","sourceRoot":"","sources":["../src/bitcoin-namespace.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bitcoin-namespace.js","sourceRoot":"","sources":["../src/bitcoin-namespace.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAG7D,2CAA2C;AAC3C,MAAM,CAAC,MAAM,iBAAiB,GAAc,QAAQ,CAAA;AAEpD;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAgB,EAAE,MAAc;IACnE,IAAI,OAAO,CAAC,SAAS,KAAK,iBAAiB,EAAE,CAAC;QAC5C,MAAM,IAAI,oBAAoB,CAAC;YAC7B,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,GAAG,MAAM,wCAAwC,OAAO,CAAC,EAAE,GAAG;SACxE,CAAC,CAAA;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,gBAAgB;IAIE;IAH7B,2CAA2C;IAClC,SAAS,GAAG,iBAAiB,CAAA;IAEtC,YAA6B,OAAgC;QAAhC,YAAO,GAAP,OAAO,CAAyB;IAAG,CAAC;IAEjE,mDAAmD;IACnD,sBAAsB,CAAC,OAAgB;QACrC,oBAAoB,CAAC,OAAO,EAAE,yCAAyC,CAAC,CAAA;IAC1E,CAAC;IAED,8DAA8D;IAC9D,WAAW;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAA;IACnC,CAAC;IAED,6CAA6C;IAC7C,WAAW,CAAC,MAAgC;QAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;IAED,uDAAuD;IACvD,KAAK,CAAC,UAAU;QACd,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAA;IACnC,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,qBAAqB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshconnect/uwc-bitcoin",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Mesh-owned Bitcoin (bip122) namespace module for Universal Wallet Connector — network-specific logic (PSBT, address/network handling, mempool broadcast) with pluggable transport adapters (Wallet Standard bitcoin:* and WalletConnect bip122), consumed by the injected and walletConnect transport connectors",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"src"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@meshconnect/uwc-types": "0.
|
|
19
|
+
"@meshconnect/uwc-types": "0.26.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"typescript": "^5.9.3"
|
package/src/adapter.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BitcoinAccount,
|
|
3
|
+
BitcoinSignMessageParams,
|
|
4
|
+
SignatureType
|
|
5
|
+
} from '@meshconnect/uwc-types'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The seam between the Bitcoin namespace module and a single transport.
|
|
9
|
+
*
|
|
10
|
+
* A concrete adapter (Phase 3) is constructed by its transport bound to an
|
|
11
|
+
* already-connected provider/session — Wallet Standard `bitcoin:*` for the
|
|
12
|
+
* injected transport, WalletConnect bip122 for the WalletConnect transport —
|
|
13
|
+
* so the port carries no `connect`/provider argument: connecting is the
|
|
14
|
+
* transport's job. Each adapter converts between these transport-agnostic
|
|
15
|
+
* domain shapes and its wallet's native interface (e.g. hex ↔ `Uint8Array`).
|
|
16
|
+
*
|
|
17
|
+
* Phase 2 locks the grounded verify-flow methods. `signPsbt` (Path B, returns a
|
|
18
|
+
* signed PSBT the module then finalizes + broadcasts) and `sendTransfer`
|
|
19
|
+
* (Path A) are added alongside their concrete adapters in Phase 3 rather than
|
|
20
|
+
* guessed here.
|
|
21
|
+
*/
|
|
22
|
+
export interface BitcoinTransportAdapter {
|
|
23
|
+
/** Enumerate the bip122 accounts available on the connected session. */
|
|
24
|
+
getAccounts(): Promise<BitcoinAccount[]>
|
|
25
|
+
|
|
26
|
+
/** Sign a message with the given account. */
|
|
27
|
+
signMessage(params: BitcoinSignMessageParams): Promise<SignatureType>
|
|
28
|
+
|
|
29
|
+
/** Release any session resources the adapter holds. Optional. */
|
|
30
|
+
disconnect?(): Promise<void>
|
|
31
|
+
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import type {
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import type {
|
|
3
|
+
BitcoinAccount,
|
|
4
|
+
BitcoinSignMessageParams,
|
|
5
|
+
Network,
|
|
6
|
+
SignatureType
|
|
7
|
+
} from '@meshconnect/uwc-types'
|
|
3
8
|
import { WalletConnectorError } from '@meshconnect/uwc-types'
|
|
4
9
|
import {
|
|
5
10
|
BitcoinNamespace,
|
|
6
11
|
assertBitcoinNetwork,
|
|
7
12
|
BITCOIN_NAMESPACE
|
|
8
13
|
} from './bitcoin-namespace'
|
|
14
|
+
import type { BitcoinTransportAdapter } from './adapter'
|
|
9
15
|
|
|
10
16
|
const bitcoinNetwork: Network = {
|
|
11
17
|
internalId: 0,
|
|
@@ -27,6 +33,21 @@ const ethereumNetwork: Network = {
|
|
|
27
33
|
networkType: 'evm'
|
|
28
34
|
}
|
|
29
35
|
|
|
36
|
+
const account: BitcoinAccount = {
|
|
37
|
+
address: 'bc1qexampleaddress',
|
|
38
|
+
publicKey: '02aabbcc',
|
|
39
|
+
purpose: 'payment'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const signature: SignatureType = { type: 'standard', signature: 'deadbeef' }
|
|
43
|
+
|
|
44
|
+
/** Minimal fake adapter so the namespace's delegation can be asserted. */
|
|
45
|
+
const fakeAdapter = (): BitcoinTransportAdapter => ({
|
|
46
|
+
getAccounts: vi.fn().mockResolvedValue([account]),
|
|
47
|
+
signMessage: vi.fn().mockResolvedValue(signature),
|
|
48
|
+
disconnect: vi.fn().mockResolvedValue(undefined)
|
|
49
|
+
})
|
|
50
|
+
|
|
30
51
|
describe('assertBitcoinNetwork', () => {
|
|
31
52
|
it('passes for a bip122 network', () => {
|
|
32
53
|
expect(() => assertBitcoinNetwork(bitcoinNetwork, 'test')).not.toThrow()
|
|
@@ -48,18 +69,51 @@ describe('assertBitcoinNetwork', () => {
|
|
|
48
69
|
describe('BitcoinNamespace', () => {
|
|
49
70
|
it('serves the bip122 namespace', () => {
|
|
50
71
|
expect(BITCOIN_NAMESPACE).toBe('bip122')
|
|
51
|
-
expect(new BitcoinNamespace().namespace).toBe(
|
|
72
|
+
expect(new BitcoinNamespace(fakeAdapter()).namespace).toBe(
|
|
73
|
+
BITCOIN_NAMESPACE
|
|
74
|
+
)
|
|
52
75
|
})
|
|
53
76
|
|
|
54
77
|
it('assertSupportedNetwork accepts a bip122 network', () => {
|
|
55
78
|
expect(() =>
|
|
56
|
-
new BitcoinNamespace().assertSupportedNetwork(bitcoinNetwork)
|
|
79
|
+
new BitcoinNamespace(fakeAdapter()).assertSupportedNetwork(bitcoinNetwork)
|
|
57
80
|
).not.toThrow()
|
|
58
81
|
})
|
|
59
82
|
|
|
60
83
|
it('assertSupportedNetwork rejects a non-bip122 network', () => {
|
|
61
84
|
expect(() =>
|
|
62
|
-
new BitcoinNamespace().assertSupportedNetwork(
|
|
85
|
+
new BitcoinNamespace(fakeAdapter()).assertSupportedNetwork(
|
|
86
|
+
ethereumNetwork
|
|
87
|
+
)
|
|
63
88
|
).toThrow(WalletConnectorError)
|
|
64
89
|
})
|
|
90
|
+
|
|
91
|
+
it('delegates getAccounts to the adapter', async () => {
|
|
92
|
+
const adapter = fakeAdapter()
|
|
93
|
+
const result = await new BitcoinNamespace(adapter).getAccounts()
|
|
94
|
+
expect(adapter.getAccounts).toHaveBeenCalledOnce()
|
|
95
|
+
expect(result).toEqual([account])
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('delegates signMessage to the adapter with the same params', async () => {
|
|
99
|
+
const adapter = fakeAdapter()
|
|
100
|
+
const params: BitcoinSignMessageParams = { account, message: 'verify me' }
|
|
101
|
+
const result = await new BitcoinNamespace(adapter).signMessage(params)
|
|
102
|
+
expect(adapter.signMessage).toHaveBeenCalledWith(params)
|
|
103
|
+
expect(result).toBe(signature)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('delegates disconnect and tolerates an adapter without one', async () => {
|
|
107
|
+
const adapter = fakeAdapter()
|
|
108
|
+
await new BitcoinNamespace(adapter).disconnect()
|
|
109
|
+
expect(adapter.disconnect).toHaveBeenCalledOnce()
|
|
110
|
+
|
|
111
|
+
const noDisconnect: BitcoinTransportAdapter = {
|
|
112
|
+
getAccounts: adapter.getAccounts,
|
|
113
|
+
signMessage: adapter.signMessage
|
|
114
|
+
}
|
|
115
|
+
await expect(
|
|
116
|
+
new BitcoinNamespace(noDisconnect).disconnect()
|
|
117
|
+
).resolves.toBeUndefined()
|
|
118
|
+
})
|
|
65
119
|
})
|
package/src/bitcoin-namespace.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
BitcoinAccount,
|
|
3
|
+
BitcoinSignMessageParams,
|
|
4
|
+
Namespace,
|
|
5
|
+
Network,
|
|
6
|
+
SignatureType
|
|
7
|
+
} from '@meshconnect/uwc-types'
|
|
2
8
|
import { WalletConnectorError } from '@meshconnect/uwc-types'
|
|
9
|
+
import type { BitcoinTransportAdapter } from './adapter'
|
|
3
10
|
|
|
4
11
|
/** CAIP-2 namespace this module serves. */
|
|
5
12
|
export const BITCOIN_NAMESPACE: Namespace = 'bip122'
|
|
@@ -25,15 +32,14 @@ export function assertBitcoinNetwork(network: Network, method: string): void {
|
|
|
25
32
|
* (`injected-connector`, `wallet-connect-connector`) own wallet discovery,
|
|
26
33
|
* pairing, and the provider/session lifecycle. This module owns only
|
|
27
34
|
* Bitcoin-specific operations performed against a transport-supplied
|
|
28
|
-
* provider/session
|
|
29
|
-
*
|
|
30
|
-
*
|
|
35
|
+
* provider/session, delegating each to the {@link BitcoinTransportAdapter} it
|
|
36
|
+
* was constructed with — the transport builds that adapter bound to the live
|
|
37
|
+
* session.
|
|
31
38
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* Phase 1 (scaffold): namespace identity + the shared network guard only.
|
|
39
|
+
* Phase 2 exposes the grounded verify-flow operations (account enumeration and
|
|
40
|
+
* message signing). PSBT signing (Path B) plus finalize/broadcast, and the
|
|
41
|
+
* high-level `sendTransfer` (Path A), land in Phase 3 alongside their concrete
|
|
42
|
+
* adapters.
|
|
37
43
|
*
|
|
38
44
|
* Phased build plan:
|
|
39
45
|
* https://app.notion.com/p/3a5f862e950a8187b3d3f0e255d13f45
|
|
@@ -42,8 +48,25 @@ export class BitcoinNamespace {
|
|
|
42
48
|
/** CAIP-2 namespace this module serves. */
|
|
43
49
|
readonly namespace = BITCOIN_NAMESPACE
|
|
44
50
|
|
|
51
|
+
constructor(private readonly adapter: BitcoinTransportAdapter) {}
|
|
52
|
+
|
|
45
53
|
/** Throws unless `network` is a bip122 network. */
|
|
46
54
|
assertSupportedNetwork(network: Network): void {
|
|
47
55
|
assertBitcoinNetwork(network, 'BitcoinNamespace.assertSupportedNetwork')
|
|
48
56
|
}
|
|
57
|
+
|
|
58
|
+
/** Enumerate the bip122 accounts on the connected session. */
|
|
59
|
+
getAccounts(): Promise<BitcoinAccount[]> {
|
|
60
|
+
return this.adapter.getAccounts()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Sign a message with the given account. */
|
|
64
|
+
signMessage(params: BitcoinSignMessageParams): Promise<SignatureType> {
|
|
65
|
+
return this.adapter.signMessage(params)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Release any session resources the adapter holds. */
|
|
69
|
+
async disconnect(): Promise<void> {
|
|
70
|
+
await this.adapter.disconnect?.()
|
|
71
|
+
}
|
|
49
72
|
}
|
package/src/index.ts
CHANGED