@meshconnect/uwc-bitcoin 0.1.0-snapshot.e930396
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/bitcoin-namespace.d.ts +36 -0
- package/dist/bitcoin-namespace.d.ts.map +1 -0
- package/dist/bitcoin-namespace.js +45 -0
- package/dist/bitcoin-namespace.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -0
- package/src/bitcoin-namespace.test.ts +65 -0
- package/src/bitcoin-namespace.ts +49 -0
- package/src/index.ts +5 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Namespace, Network } from '@meshconnect/uwc-types';
|
|
2
|
+
/** CAIP-2 namespace this module serves. */
|
|
3
|
+
export declare const BITCOIN_NAMESPACE: Namespace;
|
|
4
|
+
/**
|
|
5
|
+
* Assert `network` is a bip122 network, else throw. Shared by the namespace
|
|
6
|
+
* module and its transport adapters so the boundary check lives in one place.
|
|
7
|
+
*/
|
|
8
|
+
export declare function assertBitcoinNetwork(network: Network, method: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* Bitcoin (bip122) namespace module.
|
|
11
|
+
*
|
|
12
|
+
* A NAMESPACE module, not a connector — and it has no `connect` of its own.
|
|
13
|
+
* Connecting belongs to the transport layer: the transport connectors
|
|
14
|
+
* (`injected-connector`, `wallet-connect-connector`) own wallet discovery,
|
|
15
|
+
* pairing, and the provider/session lifecycle. This module owns only
|
|
16
|
+
* Bitcoin-specific operations performed against a transport-supplied
|
|
17
|
+
* provider/session — enumerating bip122 accounts, signing messages,
|
|
18
|
+
* building/signing/finalizing PSBTs, and broadcasting. Both transports
|
|
19
|
+
* dispatch their `bip122` branch into the matching adapter here.
|
|
20
|
+
*
|
|
21
|
+
* Those operations, and the provider/session types they take, land on the
|
|
22
|
+
* `BitcoinTransportAdapter` port in Phase 2 — deferred here so the scaffold
|
|
23
|
+
* doesn't pre-commit signatures before those types exist.
|
|
24
|
+
*
|
|
25
|
+
* Phase 1 (scaffold): namespace identity + the shared network guard only.
|
|
26
|
+
*
|
|
27
|
+
* Phased build plan:
|
|
28
|
+
* https://app.notion.com/p/3a5f862e950a8187b3d3f0e255d13f45
|
|
29
|
+
*/
|
|
30
|
+
export declare class BitcoinNamespace {
|
|
31
|
+
/** CAIP-2 namespace this module serves. */
|
|
32
|
+
readonly namespace: Namespace;
|
|
33
|
+
/** Throws unless `network` is a bip122 network. */
|
|
34
|
+
assertSupportedNetwork(network: Network): void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=bitcoin-namespace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitcoin-namespace.d.ts","sourceRoot":"","sources":["../src/bitcoin-namespace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAGhE,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;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,gBAAgB;IAC3B,2CAA2C;IAC3C,QAAQ,CAAC,SAAS,YAAoB;IAEtC,mDAAmD;IACnD,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;CAG/C"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { WalletConnectorError } from '@meshconnect/uwc-types';
|
|
2
|
+
/** CAIP-2 namespace this module serves. */
|
|
3
|
+
export const BITCOIN_NAMESPACE = 'bip122';
|
|
4
|
+
/**
|
|
5
|
+
* Assert `network` is a bip122 network, else throw. Shared by the namespace
|
|
6
|
+
* module and its transport adapters so the boundary check lives in one place.
|
|
7
|
+
*/
|
|
8
|
+
export function assertBitcoinNetwork(network, method) {
|
|
9
|
+
if (network.namespace !== BITCOIN_NAMESPACE) {
|
|
10
|
+
throw new WalletConnectorError({
|
|
11
|
+
type: 'unknown',
|
|
12
|
+
message: `${method}: expected a bip122 network but got "${network.id}"`
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Bitcoin (bip122) namespace module.
|
|
18
|
+
*
|
|
19
|
+
* A NAMESPACE module, not a connector — and it has no `connect` of its own.
|
|
20
|
+
* Connecting belongs to the transport layer: the transport connectors
|
|
21
|
+
* (`injected-connector`, `wallet-connect-connector`) own wallet discovery,
|
|
22
|
+
* pairing, and the provider/session lifecycle. This module owns only
|
|
23
|
+
* Bitcoin-specific operations performed against a transport-supplied
|
|
24
|
+
* provider/session — enumerating bip122 accounts, signing messages,
|
|
25
|
+
* building/signing/finalizing PSBTs, and broadcasting. Both transports
|
|
26
|
+
* dispatch their `bip122` branch into the matching adapter here.
|
|
27
|
+
*
|
|
28
|
+
* Those operations, and the provider/session types they take, land on the
|
|
29
|
+
* `BitcoinTransportAdapter` port in Phase 2 — deferred here so the scaffold
|
|
30
|
+
* doesn't pre-commit signatures before those types exist.
|
|
31
|
+
*
|
|
32
|
+
* Phase 1 (scaffold): namespace identity + the shared network guard only.
|
|
33
|
+
*
|
|
34
|
+
* Phased build plan:
|
|
35
|
+
* https://app.notion.com/p/3a5f862e950a8187b3d3f0e255d13f45
|
|
36
|
+
*/
|
|
37
|
+
export class BitcoinNamespace {
|
|
38
|
+
/** CAIP-2 namespace this module serves. */
|
|
39
|
+
namespace = BITCOIN_NAMESPACE;
|
|
40
|
+
/** Throws unless `network` is a bip122 network. */
|
|
41
|
+
assertSupportedNetwork(network) {
|
|
42
|
+
assertBitcoinNetwork(network, 'BitcoinNamespace.assertSupportedNetwork');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=bitcoin-namespace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitcoin-namespace.js","sourceRoot":"","sources":["../src/bitcoin-namespace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAE7D,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;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,gBAAgB;IAC3B,2CAA2C;IAClC,SAAS,GAAG,iBAAiB,CAAA;IAEtC,mDAAmD;IACnD,sBAAsB,CAAC,OAAgB;QACrC,oBAAoB,CAAC,OAAO,EAAE,yCAAyC,CAAC,CAAA;IAC1E,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,qBAAqB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@meshconnect/uwc-bitcoin",
|
|
3
|
+
"version": "0.1.0-snapshot.e930396",
|
|
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
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@meshconnect/uwc-types": "0.23.0-snapshot.e930396"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"typescript": "^5.9.3"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc",
|
|
29
|
+
"dev": "tsc --watch",
|
|
30
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
31
|
+
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
32
|
+
"type-check": "tsc --noEmit"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import type { Network } from '@meshconnect/uwc-types'
|
|
3
|
+
import { WalletConnectorError } from '@meshconnect/uwc-types'
|
|
4
|
+
import {
|
|
5
|
+
BitcoinNamespace,
|
|
6
|
+
assertBitcoinNetwork,
|
|
7
|
+
BITCOIN_NAMESPACE
|
|
8
|
+
} from './bitcoin-namespace'
|
|
9
|
+
|
|
10
|
+
const bitcoinNetwork: Network = {
|
|
11
|
+
internalId: 0,
|
|
12
|
+
id: 'bip122:000000000019d6689c085ae165831e93',
|
|
13
|
+
namespace: 'bip122',
|
|
14
|
+
name: 'Bitcoin',
|
|
15
|
+
logoUrl: '',
|
|
16
|
+
nativeCurrency: { name: 'Satoshi', symbol: 'BTC', decimals: 8 },
|
|
17
|
+
networkType: 'bitcoin'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ethereumNetwork: Network = {
|
|
21
|
+
internalId: 1,
|
|
22
|
+
id: 'eip155:1',
|
|
23
|
+
namespace: 'eip155',
|
|
24
|
+
name: 'Ethereum',
|
|
25
|
+
logoUrl: '',
|
|
26
|
+
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
|
|
27
|
+
networkType: 'evm'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('assertBitcoinNetwork', () => {
|
|
31
|
+
it('passes for a bip122 network', () => {
|
|
32
|
+
expect(() => assertBitcoinNetwork(bitcoinNetwork, 'test')).not.toThrow()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('throws a WalletConnectorError for a non-bip122 network', () => {
|
|
36
|
+
expect(() => assertBitcoinNetwork(ethereumNetwork, 'test')).toThrow(
|
|
37
|
+
WalletConnectorError
|
|
38
|
+
)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('names the offending network id in the message', () => {
|
|
42
|
+
expect(() => assertBitcoinNetwork(ethereumNetwork, 'test')).toThrow(
|
|
43
|
+
ethereumNetwork.id
|
|
44
|
+
)
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
describe('BitcoinNamespace', () => {
|
|
49
|
+
it('serves the bip122 namespace', () => {
|
|
50
|
+
expect(BITCOIN_NAMESPACE).toBe('bip122')
|
|
51
|
+
expect(new BitcoinNamespace().namespace).toBe(BITCOIN_NAMESPACE)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('assertSupportedNetwork accepts a bip122 network', () => {
|
|
55
|
+
expect(() =>
|
|
56
|
+
new BitcoinNamespace().assertSupportedNetwork(bitcoinNetwork)
|
|
57
|
+
).not.toThrow()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('assertSupportedNetwork rejects a non-bip122 network', () => {
|
|
61
|
+
expect(() =>
|
|
62
|
+
new BitcoinNamespace().assertSupportedNetwork(ethereumNetwork)
|
|
63
|
+
).toThrow(WalletConnectorError)
|
|
64
|
+
})
|
|
65
|
+
})
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Namespace, Network } from '@meshconnect/uwc-types'
|
|
2
|
+
import { WalletConnectorError } from '@meshconnect/uwc-types'
|
|
3
|
+
|
|
4
|
+
/** CAIP-2 namespace this module serves. */
|
|
5
|
+
export const BITCOIN_NAMESPACE: Namespace = 'bip122'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Assert `network` is a bip122 network, else throw. Shared by the namespace
|
|
9
|
+
* module and its transport adapters so the boundary check lives in one place.
|
|
10
|
+
*/
|
|
11
|
+
export function assertBitcoinNetwork(network: Network, method: string): void {
|
|
12
|
+
if (network.namespace !== BITCOIN_NAMESPACE) {
|
|
13
|
+
throw new WalletConnectorError({
|
|
14
|
+
type: 'unknown',
|
|
15
|
+
message: `${method}: expected a bip122 network but got "${network.id}"`
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Bitcoin (bip122) namespace module.
|
|
22
|
+
*
|
|
23
|
+
* A NAMESPACE module, not a connector — and it has no `connect` of its own.
|
|
24
|
+
* Connecting belongs to the transport layer: the transport connectors
|
|
25
|
+
* (`injected-connector`, `wallet-connect-connector`) own wallet discovery,
|
|
26
|
+
* pairing, and the provider/session lifecycle. This module owns only
|
|
27
|
+
* Bitcoin-specific operations performed against a transport-supplied
|
|
28
|
+
* provider/session — enumerating bip122 accounts, signing messages,
|
|
29
|
+
* building/signing/finalizing PSBTs, and broadcasting. Both transports
|
|
30
|
+
* dispatch their `bip122` branch into the matching adapter here.
|
|
31
|
+
*
|
|
32
|
+
* Those operations, and the provider/session types they take, land on the
|
|
33
|
+
* `BitcoinTransportAdapter` port in Phase 2 — deferred here so the scaffold
|
|
34
|
+
* doesn't pre-commit signatures before those types exist.
|
|
35
|
+
*
|
|
36
|
+
* Phase 1 (scaffold): namespace identity + the shared network guard only.
|
|
37
|
+
*
|
|
38
|
+
* Phased build plan:
|
|
39
|
+
* https://app.notion.com/p/3a5f862e950a8187b3d3f0e255d13f45
|
|
40
|
+
*/
|
|
41
|
+
export class BitcoinNamespace {
|
|
42
|
+
/** CAIP-2 namespace this module serves. */
|
|
43
|
+
readonly namespace = BITCOIN_NAMESPACE
|
|
44
|
+
|
|
45
|
+
/** Throws unless `network` is a bip122 network. */
|
|
46
|
+
assertSupportedNetwork(network: Network): void {
|
|
47
|
+
assertBitcoinNetwork(network, 'BitcoinNamespace.assertSupportedNetwork')
|
|
48
|
+
}
|
|
49
|
+
}
|