@ckb-ccc/okx 0.0.12-alpha.1 → 0.0.12-alpha.7
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/CHANGELOG.md +9 -0
- package/dist/advancedBarrel.d.ts +1 -1
- package/dist/advancedBarrel.d.ts.map +1 -1
- package/dist/btc/index.d.ts.map +1 -1
- package/dist/btc/index.js +23 -11
- package/dist/nostr/index.d.ts.map +1 -1
- package/dist/nostr/index.js +15 -1
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +40 -19
- package/dist.commonjs/advancedBarrel.d.ts +36 -31
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +30 -14
- package/dist.commonjs/btc/index.d.ts +42 -38
- package/dist.commonjs/btc/index.d.ts.map +1 -1
- package/dist.commonjs/btc/index.js +141 -117
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +40 -19
- package/dist.commonjs/nostr/index.d.ts +9 -9
- package/dist.commonjs/nostr/index.d.ts.map +1 -1
- package/dist.commonjs/nostr/index.js +47 -33
- package/dist.commonjs/signersFactory.d.ts +5 -2
- package/dist.commonjs/signersFactory.js +18 -14
- package/package.json +8 -9
- package/src/advancedBarrel.ts +3 -1
- package/src/btc/index.ts +26 -10
- package/src/nostr/index.ts +18 -1
package/CHANGELOG.md
ADDED
package/dist/advancedBarrel.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Nip07A } from "@ckb-ccc/nip07/advanced";
|
|
2
2
|
import { UniSatA } from "@ckb-ccc/uni-sat/advanced";
|
|
3
|
-
export interface BitcoinProvider extends UniSatA.Provider {
|
|
3
|
+
export interface BitcoinProvider extends Pick<UniSatA.Provider, "on" | "removeListener" | "signMessage">, Partial<Omit<UniSatA.Provider, "on" | "removeListener" | "signMessage">> {
|
|
4
4
|
connect?(): Promise<{
|
|
5
5
|
address: string;
|
|
6
6
|
publicKey: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEpD,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEpD,MAAM,WAAW,eACf,SAAQ,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,GAAG,gBAAgB,GAAG,aAAa,CAAC,EACrE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,GAAG,gBAAgB,GAAG,aAAa,CAAC,CAAC;IAC1E,OAAO,CAAC,IAAI,OAAO,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,mBAAmB,EAAE,MAAM,CAAC;KAC7B,CAAC,CAAC;IAEH,kBAAkB,CAAC,IAAI,OAAO,CAAC;QAC7B,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,mBAAmB,EAAE,MAAM,CAAC;KAC7B,GAAG,IAAI,CAAC,CAAC;CACX;AAED,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,QAAQ;IACpD,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;OAEG;IACH,EAAE,EAAE,aAAa,CAAC;IAElB;;;;;OAKG;IACH,cAAc,CACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GACxC,aAAa,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/E"}
|
package/dist/btc/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,GAAG,CAAC,SAAS;aAU5B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAC1D,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAVpC,OAAO,CAAC,OAAO,CAAgB;IAE/B;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EACzC,iBAAiB,GAAE,GAAG,CAAC,iBAAiB,EAWxD;IAKH,IAAI,QAAQ,IAAI,eAAe,CAwB9B;IAED;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,GAAG,CAAC,SAAS;aAU5B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAC1D,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAVpC,OAAO,CAAC,OAAO,CAAgB;IAE/B;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EACzC,iBAAiB,GAAE,GAAG,CAAC,iBAAiB,EAWxD;IAKH,IAAI,QAAQ,IAAI,eAAe,CAwB9B;IAED;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAoBtC;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAgBzC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAc9B,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAe5C;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAqBrC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAMvE"}
|
package/dist/btc/index.js
CHANGED
|
@@ -49,6 +49,13 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
49
49
|
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
50
50
|
*/
|
|
51
51
|
async getBtcAccount() {
|
|
52
|
+
if (this.provider.getAccounts) {
|
|
53
|
+
const address = (await this.provider.getAccounts())[0];
|
|
54
|
+
if (!address) {
|
|
55
|
+
throw Error("Not connected");
|
|
56
|
+
}
|
|
57
|
+
return address;
|
|
58
|
+
}
|
|
52
59
|
if (this.provider.getSelectedAccount) {
|
|
53
60
|
const account = await this.provider.getSelectedAccount();
|
|
54
61
|
if (!account) {
|
|
@@ -56,17 +63,16 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
56
63
|
}
|
|
57
64
|
return account.address;
|
|
58
65
|
}
|
|
59
|
-
|
|
60
|
-
if (!address) {
|
|
61
|
-
throw Error("Not connected");
|
|
62
|
-
}
|
|
63
|
-
return address;
|
|
66
|
+
throw Error("Unsupported OKX provider");
|
|
64
67
|
}
|
|
65
68
|
/**
|
|
66
69
|
* Gets the Bitcoin public key.
|
|
67
70
|
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
68
71
|
*/
|
|
69
72
|
async getBtcPublicKey() {
|
|
73
|
+
if (this.provider.getPublicKey) {
|
|
74
|
+
return ccc.hexFrom(await this.provider.getPublicKey());
|
|
75
|
+
}
|
|
70
76
|
if (this.provider.getSelectedAccount) {
|
|
71
77
|
const account = await this.provider.getSelectedAccount();
|
|
72
78
|
if (!account) {
|
|
@@ -74,18 +80,22 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
74
80
|
}
|
|
75
81
|
return ccc.hexFrom(account.compressedPublicKey);
|
|
76
82
|
}
|
|
77
|
-
|
|
83
|
+
throw Error("Unsupported OKX provider");
|
|
78
84
|
}
|
|
79
85
|
/**
|
|
80
86
|
* Connects to the provider by requesting accounts.
|
|
81
87
|
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
82
88
|
*/
|
|
83
89
|
async connect() {
|
|
90
|
+
if (this.provider.requestAccounts) {
|
|
91
|
+
await this.provider.requestAccounts();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
84
94
|
if (this.provider.connect) {
|
|
85
95
|
await this.provider.connect();
|
|
86
96
|
return;
|
|
87
97
|
}
|
|
88
|
-
|
|
98
|
+
throw Error("Unsupported OKX provider");
|
|
89
99
|
}
|
|
90
100
|
onReplaced(listener) {
|
|
91
101
|
const stop = [];
|
|
@@ -110,13 +120,15 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
110
120
|
catch (_) {
|
|
111
121
|
return false;
|
|
112
122
|
}
|
|
113
|
-
if (this.provider.
|
|
114
|
-
if ((await this.provider.
|
|
123
|
+
if (this.provider.getAccounts) {
|
|
124
|
+
if ((await this.provider.getAccounts()).length === 0) {
|
|
115
125
|
return false;
|
|
116
126
|
}
|
|
117
127
|
}
|
|
118
|
-
else if (
|
|
119
|
-
|
|
128
|
+
else if (this.provider.getSelectedAccount) {
|
|
129
|
+
if ((await this.provider.getSelectedAccount()) === null) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
120
132
|
}
|
|
121
133
|
await this.connect();
|
|
122
134
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nostr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,GAAG,CAAC,WAAW;aAK5B,QAAQ,EAAE,aAAa;IAJzC,OAAO,CAAC,cAAc,CAAC,CAA8B;gBAGnD,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,aAAa;IAKnC,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nostr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,GAAG,CAAC,WAAW;aAK5B,QAAQ,EAAE,aAAa;IAJzC,OAAO,CAAC,cAAc,CAAC,CAA8B;gBAGnD,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,aAAa;IAKnC,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAsBrC,cAAc,CAClB,KAAK,EAAE,GAAG,CAAC,UAAU,GACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAO9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAM9B,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAetC,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAGtC"}
|
package/dist/nostr/index.js
CHANGED
|
@@ -12,7 +12,20 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
12
12
|
}
|
|
13
13
|
async getNostrPublicKey() {
|
|
14
14
|
if (!this.publicKeyCache) {
|
|
15
|
-
this.publicKeyCache = this.provider
|
|
15
|
+
this.publicKeyCache = this.provider
|
|
16
|
+
.getPublicKey()
|
|
17
|
+
.then((v) => {
|
|
18
|
+
// For some account types of OKX Wallet, this might returns null
|
|
19
|
+
// e.g. Keyless accounts
|
|
20
|
+
if (v) {
|
|
21
|
+
return v;
|
|
22
|
+
}
|
|
23
|
+
throw Error("This OKX Wallet account does not support Nostr");
|
|
24
|
+
})
|
|
25
|
+
.catch((e) => {
|
|
26
|
+
this.publicKeyCache = undefined;
|
|
27
|
+
throw e;
|
|
28
|
+
});
|
|
16
29
|
}
|
|
17
30
|
return ccc.hexFrom(await this.publicKeyCache);
|
|
18
31
|
}
|
|
@@ -24,6 +37,7 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
24
37
|
}
|
|
25
38
|
async connect() {
|
|
26
39
|
await this.provider.connect?.(); // Help extension to switch network
|
|
40
|
+
await this.getNostrPublicKey();
|
|
27
41
|
}
|
|
28
42
|
onReplaced(listener) {
|
|
29
43
|
const stop = [];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * as OkxA from "./advancedBarrel.js";
|
|
2
|
-
//# sourceMappingURL=advanced.d.ts.map
|
|
2
|
+
//# sourceMappingURL=advanced.d.ts.map
|
|
@@ -1,27 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}
|
|
21
|
+
: function (o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
});
|
|
25
|
+
var __setModuleDefault =
|
|
26
|
+
(this && this.__setModuleDefault) ||
|
|
27
|
+
(Object.create
|
|
28
|
+
? function (o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}
|
|
31
|
+
: function (o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar =
|
|
35
|
+
(this && this.__importStar) ||
|
|
36
|
+
function (mod) {
|
|
19
37
|
if (mod && mod.__esModule) return mod;
|
|
20
38
|
var result = {};
|
|
21
|
-
if (mod != null)
|
|
39
|
+
if (mod != null)
|
|
40
|
+
for (var k in mod)
|
|
41
|
+
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
42
|
+
__createBinding(result, mod, k);
|
|
22
43
|
__setModuleDefault(result, mod);
|
|
23
44
|
return result;
|
|
24
|
-
};
|
|
45
|
+
};
|
|
25
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
47
|
exports.OkxA = void 0;
|
|
27
48
|
exports.OkxA = __importStar(require("./advancedBarrel.js"));
|
|
@@ -1,42 +1,47 @@
|
|
|
1
1
|
import { Nip07A } from "@ckb-ccc/nip07/advanced";
|
|
2
2
|
import { UniSatA } from "@ckb-ccc/uni-sat/advanced";
|
|
3
|
-
export interface BitcoinProvider
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
export interface BitcoinProvider
|
|
4
|
+
extends Pick<UniSatA.Provider, "on" | "removeListener" | "signMessage">,
|
|
5
|
+
Partial<Omit<UniSatA.Provider, "on" | "removeListener" | "signMessage">> {
|
|
6
|
+
connect?(): Promise<{
|
|
7
|
+
address: string;
|
|
8
|
+
publicKey: string;
|
|
9
|
+
compressedPublicKey: string;
|
|
10
|
+
}>;
|
|
11
|
+
getSelectedAccount?(): Promise<{
|
|
12
|
+
address: string;
|
|
13
|
+
publicKey: string;
|
|
14
|
+
compressedPublicKey: string;
|
|
15
|
+
} | null>;
|
|
14
16
|
}
|
|
15
17
|
export interface NostrProvider extends Nip07A.Provider {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
connect?(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Adds an event listener to the provider.
|
|
21
|
+
*/
|
|
22
|
+
on: NostrOnMethod;
|
|
23
|
+
/**
|
|
24
|
+
* Removes an event listener from the provider.
|
|
25
|
+
* @param eventName - The name of the event to remove the listener from.
|
|
26
|
+
* @param listener - The listener function to remove.
|
|
27
|
+
* @returns The provider instance.
|
|
28
|
+
*/
|
|
29
|
+
removeListener(
|
|
30
|
+
eventName: string,
|
|
31
|
+
listener: (...args: unknown[]) => unknown,
|
|
32
|
+
): NostrProvider;
|
|
28
33
|
}
|
|
29
34
|
/**
|
|
30
35
|
* Interface representing a method to add event listeners to the provider.
|
|
31
36
|
* @interface
|
|
32
37
|
*/
|
|
33
38
|
export interface NostrOnMethod {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Adds an event listener to the provider.
|
|
41
|
+
* @param eventName - The name of the event.
|
|
42
|
+
* @param listener - The listener function.
|
|
43
|
+
* @returns The provider instance.
|
|
44
|
+
*/
|
|
45
|
+
(eventName: string, listener: (...args: unknown[]) => unknown): Promise<void>;
|
|
41
46
|
}
|
|
42
|
-
//# sourceMappingURL=advancedBarrel.d.ts.map
|
|
47
|
+
//# sourceMappingURL=advancedBarrel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEpD,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEpD,MAAM,WAAW,eACf,SAAQ,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,GAAG,gBAAgB,GAAG,aAAa,CAAC,EACrE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,GAAG,gBAAgB,GAAG,aAAa,CAAC,CAAC;IAC1E,OAAO,CAAC,IAAI,OAAO,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,mBAAmB,EAAE,MAAM,CAAC;KAC7B,CAAC,CAAC;IAEH,kBAAkB,CAAC,IAAI,OAAO,CAAC;QAC7B,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,mBAAmB,EAAE,MAAM,CAAC;KAC7B,GAAG,IAAI,CAAC,CAAC;CACX;AAED,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,QAAQ;IACpD,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;OAEG;IACH,EAAE,EAAE,aAAa,CAAC;IAElB;;;;;OAKG;IACH,cAAc,CACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GACxC,aAAa,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/E"}
|
package/dist.commonjs/barrel.js
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}
|
|
21
|
+
: function (o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
});
|
|
25
|
+
var __exportStar =
|
|
26
|
+
(this && this.__exportStar) ||
|
|
27
|
+
function (m, exports) {
|
|
28
|
+
for (var p in m)
|
|
29
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
30
|
+
__createBinding(exports, m, p);
|
|
31
|
+
};
|
|
16
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
33
|
__exportStar(require("./btc/index.js"), exports);
|
|
18
34
|
__exportStar(require("./signersFactory.js"), exports);
|
|
@@ -6,42 +6,46 @@ import { BitcoinProvider } from "../advancedBarrel.js";
|
|
|
6
6
|
* @extends {ccc.SignerBtc}
|
|
7
7
|
*/
|
|
8
8
|
export declare class BitcoinSigner extends ccc.SignerBtc {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
9
|
+
readonly providers: Record<string, BitcoinProvider>;
|
|
10
|
+
private readonly preferredNetworks;
|
|
11
|
+
private network;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of Signer.
|
|
14
|
+
* @param {ccc.Client} client - The client instance.
|
|
15
|
+
* @param {Provider} provider - The provider instance.
|
|
16
|
+
*/
|
|
17
|
+
constructor(
|
|
18
|
+
client: ccc.Client,
|
|
19
|
+
providers: Record<string, BitcoinProvider>,
|
|
20
|
+
preferredNetworks?: ccc.NetworkPreference[],
|
|
21
|
+
);
|
|
22
|
+
get provider(): BitcoinProvider;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the Bitcoin account address.
|
|
25
|
+
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
26
|
+
*/
|
|
27
|
+
getBtcAccount(): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the Bitcoin public key.
|
|
30
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
31
|
+
*/
|
|
32
|
+
getBtcPublicKey(): Promise<ccc.Hex>;
|
|
33
|
+
/**
|
|
34
|
+
* Connects to the provider by requesting accounts.
|
|
35
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
36
|
+
*/
|
|
37
|
+
connect(): Promise<void>;
|
|
38
|
+
onReplaced(listener: () => void): () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if the signer is connected.
|
|
41
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
42
|
+
*/
|
|
43
|
+
isConnected(): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Signs a raw message with the Bitcoin account.
|
|
46
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
47
|
+
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
48
|
+
*/
|
|
49
|
+
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
46
50
|
}
|
|
47
|
-
//# sourceMappingURL=index.d.ts.map
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,GAAG,CAAC,SAAS;aAU5B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAC1D,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAVpC,OAAO,CAAC,OAAO,CAAgB;IAE/B;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EACzC,iBAAiB,GAAE,GAAG,CAAC,iBAAiB,EAWxD;IAKH,IAAI,QAAQ,IAAI,eAAe,CAwB9B;IAED;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,GAAG,CAAC,SAAS;aAU5B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAC1D,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAVpC,OAAO,CAAC,OAAO,CAAgB;IAE/B;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EACzC,iBAAiB,GAAE,GAAG,CAAC,iBAAiB,EAWxD;IAKH,IAAI,QAAQ,IAAI,eAAe,CAwB9B;IAED;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAoBtC;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAgBzC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAc9B,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAe5C;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAqBrC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAMvE"}
|
|
@@ -8,130 +8,154 @@ const core_1 = require("@ckb-ccc/core");
|
|
|
8
8
|
* @extends {ccc.SignerBtc}
|
|
9
9
|
*/
|
|
10
10
|
class BitcoinSigner extends core_1.ccc.SignerBtc {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of Signer.
|
|
13
|
+
* @param {ccc.Client} client - The client instance.
|
|
14
|
+
* @param {Provider} provider - The provider instance.
|
|
15
|
+
*/
|
|
16
|
+
constructor(
|
|
17
|
+
client,
|
|
18
|
+
providers,
|
|
19
|
+
preferredNetworks = [
|
|
20
|
+
{
|
|
21
|
+
addressPrefix: "ckb",
|
|
22
|
+
signerType: core_1.ccc.SignerType.BTC,
|
|
23
|
+
network: "btc",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
addressPrefix: "ckt",
|
|
27
|
+
signerType: core_1.ccc.SignerType.BTC,
|
|
28
|
+
network: "btcTestnet",
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
) {
|
|
32
|
+
super(client);
|
|
33
|
+
this.providers = providers;
|
|
34
|
+
this.preferredNetworks = preferredNetworks;
|
|
35
|
+
this.network = "btcTestnet";
|
|
36
|
+
}
|
|
37
|
+
get provider() {
|
|
38
|
+
const { network } = this.matchNetworkPreference(
|
|
39
|
+
this.preferredNetworks,
|
|
40
|
+
this.network,
|
|
41
|
+
) ?? { network: this.network };
|
|
42
|
+
this.network = network;
|
|
43
|
+
const chain = {
|
|
44
|
+
btc: "bitcoin",
|
|
45
|
+
btcTestnet: "bitcoinTestnet",
|
|
46
|
+
btcSignet: "bitcoinSignet",
|
|
47
|
+
}[network];
|
|
48
|
+
if (!chain) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`OKX wallet doesn't support the requested chain ${this.network}`,
|
|
51
|
+
);
|
|
32
52
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
btcTestnet: "bitcoinTestnet",
|
|
39
|
-
btcSignet: "bitcoinSignet",
|
|
40
|
-
}[network];
|
|
41
|
-
if (!chain) {
|
|
42
|
-
throw new Error(`OKX wallet doesn't support the requested chain ${this.network}`);
|
|
43
|
-
}
|
|
44
|
-
const provider = this.providers[chain];
|
|
45
|
-
if (!provider) {
|
|
46
|
-
throw new Error(`OKX wallet doesn't support the requested chain ${this.network}`);
|
|
47
|
-
}
|
|
48
|
-
return provider;
|
|
53
|
+
const provider = this.providers[chain];
|
|
54
|
+
if (!provider) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`OKX wallet doesn't support the requested chain ${this.network}`,
|
|
57
|
+
);
|
|
49
58
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!address) {
|
|
64
|
-
throw Error("Not connected");
|
|
65
|
-
}
|
|
66
|
-
return address;
|
|
59
|
+
return provider;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Gets the Bitcoin account address.
|
|
63
|
+
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
64
|
+
*/
|
|
65
|
+
async getBtcAccount() {
|
|
66
|
+
if (this.provider.getAccounts) {
|
|
67
|
+
const address = (await this.provider.getAccounts())[0];
|
|
68
|
+
if (!address) {
|
|
69
|
+
throw Error("Not connected");
|
|
70
|
+
}
|
|
71
|
+
return address;
|
|
67
72
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const account = await this.provider.getSelectedAccount();
|
|
75
|
-
if (!account) {
|
|
76
|
-
throw Error("Not connected");
|
|
77
|
-
}
|
|
78
|
-
return core_1.ccc.hexFrom(account.compressedPublicKey);
|
|
79
|
-
}
|
|
80
|
-
return core_1.ccc.hexFrom(await this.provider.getPublicKey());
|
|
73
|
+
if (this.provider.getSelectedAccount) {
|
|
74
|
+
const account = await this.provider.getSelectedAccount();
|
|
75
|
+
if (!account) {
|
|
76
|
+
throw Error("Not connected");
|
|
77
|
+
}
|
|
78
|
+
return account.address;
|
|
81
79
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
await this.provider.requestAccounts();
|
|
80
|
+
throw Error("Unsupported OKX provider");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Gets the Bitcoin public key.
|
|
84
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
85
|
+
*/
|
|
86
|
+
async getBtcPublicKey() {
|
|
87
|
+
if (this.provider.getPublicKey) {
|
|
88
|
+
return core_1.ccc.hexFrom(await this.provider.getPublicKey());
|
|
92
89
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
stop.push(() => {
|
|
100
|
-
this.provider.removeListener("accountChanged", replacer);
|
|
101
|
-
});
|
|
102
|
-
this.provider.on("accountChanged", replacer);
|
|
103
|
-
return stop[0];
|
|
90
|
+
if (this.provider.getSelectedAccount) {
|
|
91
|
+
const account = await this.provider.getSelectedAccount();
|
|
92
|
+
if (!account) {
|
|
93
|
+
throw Error("Not connected");
|
|
94
|
+
}
|
|
95
|
+
return core_1.ccc.hexFrom(account.compressedPublicKey);
|
|
104
96
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
if (this.provider.getSelectedAccount) {
|
|
117
|
-
if ((await this.provider.getSelectedAccount()) === null) {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
else if ((await this.provider.getAccounts()).length === 0) {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
await this.connect();
|
|
125
|
-
return true;
|
|
97
|
+
throw Error("Unsupported OKX provider");
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Connects to the provider by requesting accounts.
|
|
101
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
102
|
+
*/
|
|
103
|
+
async connect() {
|
|
104
|
+
if (this.provider.requestAccounts) {
|
|
105
|
+
await this.provider.requestAccounts();
|
|
106
|
+
return;
|
|
126
107
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
131
|
-
*/
|
|
132
|
-
async signMessageRaw(message) {
|
|
133
|
-
const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
|
|
134
|
-
return this.provider.signMessage(challenge, "ecdsa");
|
|
108
|
+
if (this.provider.connect) {
|
|
109
|
+
await this.provider.connect();
|
|
110
|
+
return;
|
|
135
111
|
}
|
|
112
|
+
throw Error("Unsupported OKX provider");
|
|
113
|
+
}
|
|
114
|
+
onReplaced(listener) {
|
|
115
|
+
const stop = [];
|
|
116
|
+
const replacer = async () => {
|
|
117
|
+
listener();
|
|
118
|
+
stop[0]?.();
|
|
119
|
+
};
|
|
120
|
+
stop.push(() => {
|
|
121
|
+
this.provider.removeListener("accountChanged", replacer);
|
|
122
|
+
});
|
|
123
|
+
this.provider.on("accountChanged", replacer);
|
|
124
|
+
return stop[0];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Checks if the signer is connected.
|
|
128
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
129
|
+
*/
|
|
130
|
+
async isConnected() {
|
|
131
|
+
try {
|
|
132
|
+
this.provider;
|
|
133
|
+
} catch (_) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
if (this.provider.getAccounts) {
|
|
137
|
+
if ((await this.provider.getAccounts()).length === 0) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
} else if (this.provider.getSelectedAccount) {
|
|
141
|
+
if ((await this.provider.getSelectedAccount()) === null) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
await this.connect();
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Signs a raw message with the Bitcoin account.
|
|
150
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
151
|
+
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
152
|
+
*/
|
|
153
|
+
async signMessageRaw(message) {
|
|
154
|
+
const challenge =
|
|
155
|
+
typeof message === "string"
|
|
156
|
+
? message
|
|
157
|
+
: core_1.ccc.hexFrom(message).slice(2);
|
|
158
|
+
return this.provider.signMessage(challenge, "ecdsa");
|
|
159
|
+
}
|
|
136
160
|
}
|
|
137
161
|
exports.BitcoinSigner = BitcoinSigner;
|
package/dist.commonjs/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * as Okx from "./barrel.js";
|
|
2
|
-
//# sourceMappingURL=index.d.ts.map
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist.commonjs/index.js
CHANGED
|
@@ -1,27 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}
|
|
21
|
+
: function (o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
});
|
|
25
|
+
var __setModuleDefault =
|
|
26
|
+
(this && this.__setModuleDefault) ||
|
|
27
|
+
(Object.create
|
|
28
|
+
? function (o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}
|
|
31
|
+
: function (o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar =
|
|
35
|
+
(this && this.__importStar) ||
|
|
36
|
+
function (mod) {
|
|
19
37
|
if (mod && mod.__esModule) return mod;
|
|
20
38
|
var result = {};
|
|
21
|
-
if (mod != null)
|
|
39
|
+
if (mod != null)
|
|
40
|
+
for (var k in mod)
|
|
41
|
+
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
42
|
+
__createBinding(result, mod, k);
|
|
22
43
|
__setModuleDefault(result, mod);
|
|
23
44
|
return result;
|
|
24
|
-
};
|
|
45
|
+
};
|
|
25
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
47
|
exports.Okx = void 0;
|
|
27
48
|
exports.Okx = __importStar(require("./barrel.js"));
|
|
@@ -6,13 +6,13 @@ import { NostrProvider } from "../advancedBarrel.js";
|
|
|
6
6
|
* @extends {ccc.SignerBtc}
|
|
7
7
|
*/
|
|
8
8
|
export declare class NostrSigner extends ccc.SignerNostr {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
readonly provider: NostrProvider;
|
|
10
|
+
private publicKeyCache?;
|
|
11
|
+
constructor(client: ccc.Client, provider: NostrProvider);
|
|
12
|
+
getNostrPublicKey(): Promise<ccc.Hex>;
|
|
13
|
+
signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
|
|
14
|
+
connect(): Promise<void>;
|
|
15
|
+
onReplaced(listener: () => void): () => void;
|
|
16
|
+
isConnected(): Promise<boolean>;
|
|
17
17
|
}
|
|
18
|
-
//# sourceMappingURL=index.d.ts.map
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nostr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,GAAG,CAAC,WAAW;aAK5B,QAAQ,EAAE,aAAa;IAJzC,OAAO,CAAC,cAAc,CAAC,CAA8B;gBAGnD,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,aAAa;IAKnC,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nostr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,GAAG,CAAC,WAAW;aAK5B,QAAQ,EAAE,aAAa;IAJzC,OAAO,CAAC,cAAc,CAAC,CAA8B;gBAGnD,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,aAAa;IAKnC,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAsBrC,cAAc,CAClB,KAAK,EAAE,GAAG,CAAC,UAAU,GACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAO9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAM9B,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAetC,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAGtC"}
|
|
@@ -8,40 +8,54 @@ const core_1 = require("@ckb-ccc/core");
|
|
|
8
8
|
* @extends {ccc.SignerBtc}
|
|
9
9
|
*/
|
|
10
10
|
class NostrSigner extends core_1.ccc.SignerNostr {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
onReplaced(listener) {
|
|
32
|
-
const stop = [];
|
|
33
|
-
const replacer = async () => {
|
|
34
|
-
listener();
|
|
35
|
-
stop[0]?.();
|
|
36
|
-
};
|
|
37
|
-
stop.push(() => {
|
|
38
|
-
this.provider.removeListener("accountChanged", replacer);
|
|
11
|
+
constructor(client, provider) {
|
|
12
|
+
super(client);
|
|
13
|
+
this.provider = provider;
|
|
14
|
+
this.publicKeyCache = undefined;
|
|
15
|
+
}
|
|
16
|
+
async getNostrPublicKey() {
|
|
17
|
+
if (!this.publicKeyCache) {
|
|
18
|
+
this.publicKeyCache = this.provider
|
|
19
|
+
.getPublicKey()
|
|
20
|
+
.then((v) => {
|
|
21
|
+
// For some account types of OKX Wallet, this might returns null
|
|
22
|
+
// e.g. Keyless accounts
|
|
23
|
+
if (v) {
|
|
24
|
+
return v;
|
|
25
|
+
}
|
|
26
|
+
throw Error("This OKX Wallet account does not support Nostr");
|
|
27
|
+
})
|
|
28
|
+
.catch((e) => {
|
|
29
|
+
this.publicKeyCache = undefined;
|
|
30
|
+
throw e;
|
|
39
31
|
});
|
|
40
|
-
this.provider.on("accountChanged", replacer);
|
|
41
|
-
return stop[0];
|
|
42
|
-
}
|
|
43
|
-
async isConnected() {
|
|
44
|
-
return true;
|
|
45
32
|
}
|
|
33
|
+
return core_1.ccc.hexFrom(await this.publicKeyCache);
|
|
34
|
+
}
|
|
35
|
+
async signNostrEvent(event) {
|
|
36
|
+
return this.provider.signEvent({
|
|
37
|
+
...event,
|
|
38
|
+
pubkey: await this.publicKeyCache,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async connect() {
|
|
42
|
+
await this.provider.connect?.(); // Help extension to switch network
|
|
43
|
+
await this.getNostrPublicKey();
|
|
44
|
+
}
|
|
45
|
+
onReplaced(listener) {
|
|
46
|
+
const stop = [];
|
|
47
|
+
const replacer = async () => {
|
|
48
|
+
listener();
|
|
49
|
+
stop[0]?.();
|
|
50
|
+
};
|
|
51
|
+
stop.push(() => {
|
|
52
|
+
this.provider.removeListener("accountChanged", replacer);
|
|
53
|
+
});
|
|
54
|
+
this.provider.on("accountChanged", replacer);
|
|
55
|
+
return stop[0];
|
|
56
|
+
}
|
|
57
|
+
async isConnected() {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
46
60
|
}
|
|
47
61
|
exports.NostrSigner = NostrSigner;
|
|
@@ -4,5 +4,8 @@ import { ccc } from "@ckb-ccc/core";
|
|
|
4
4
|
* @param {ccc.Client} client - The client instance.
|
|
5
5
|
* @returns {BitcoinSigner | undefined} The BitcoinSigner instance if the OKX wallet is available, otherwise undefined.
|
|
6
6
|
*/
|
|
7
|
-
export declare function getOKXSigners(
|
|
8
|
-
|
|
7
|
+
export declare function getOKXSigners(
|
|
8
|
+
client: ccc.Client,
|
|
9
|
+
preferredNetworks?: ccc.NetworkPreference[],
|
|
10
|
+
): ccc.SignerInfo[];
|
|
11
|
+
//# sourceMappingURL=signersFactory.d.ts.map
|
|
@@ -9,19 +9,23 @@ const index_js_2 = require("./nostr/index.js");
|
|
|
9
9
|
* @returns {BitcoinSigner | undefined} The BitcoinSigner instance if the OKX wallet is available, otherwise undefined.
|
|
10
10
|
*/
|
|
11
11
|
function getOKXSigners(client, preferredNetworks) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
const windowRef = window;
|
|
13
|
+
if (typeof windowRef.okxwallet === "undefined") {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
return [
|
|
17
|
+
{
|
|
18
|
+
signer: new index_js_1.BitcoinSigner(
|
|
19
|
+
client,
|
|
20
|
+
windowRef.okxwallet,
|
|
21
|
+
preferredNetworks,
|
|
22
|
+
),
|
|
23
|
+
name: "BTC",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
signer: new index_js_2.NostrSigner(client, windowRef.okxwallet.nostr),
|
|
27
|
+
name: "Nostr",
|
|
28
|
+
},
|
|
29
|
+
];
|
|
26
30
|
}
|
|
27
31
|
exports.getOKXSigners = getOKXSigners;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/okx",
|
|
3
|
-
"version": "0.0.12-alpha.
|
|
3
|
+
"version": "0.0.12-alpha.7",
|
|
4
4
|
"description": "CCC - CKBer's Codebase. Common Chains Connector's support for OKX",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,11 +22,6 @@
|
|
|
22
22
|
"default": "./dist.commonjs/advanced.js"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
|
|
27
|
-
"lint": "eslint",
|
|
28
|
-
"format": "prettier --write . && eslint --fix"
|
|
29
|
-
},
|
|
30
25
|
"devDependencies": {
|
|
31
26
|
"@eslint/js": "^9.1.1",
|
|
32
27
|
"copyfiles": "^2.4.1",
|
|
@@ -44,8 +39,12 @@
|
|
|
44
39
|
},
|
|
45
40
|
"dependencies": {
|
|
46
41
|
"@ckb-ccc/core": "0.0.12-alpha.1",
|
|
47
|
-
"@ckb-ccc/nip07": "0.0.12-alpha.
|
|
42
|
+
"@ckb-ccc/nip07": "0.0.12-alpha.2",
|
|
48
43
|
"@ckb-ccc/uni-sat": "0.0.12-alpha.1"
|
|
49
44
|
},
|
|
50
|
-
"
|
|
51
|
-
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
|
|
47
|
+
"lint": "eslint",
|
|
48
|
+
"format": "prettier --write . && eslint --fix"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/advancedBarrel.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Nip07A } from "@ckb-ccc/nip07/advanced";
|
|
2
2
|
import { UniSatA } from "@ckb-ccc/uni-sat/advanced";
|
|
3
3
|
|
|
4
|
-
export interface BitcoinProvider
|
|
4
|
+
export interface BitcoinProvider
|
|
5
|
+
extends Pick<UniSatA.Provider, "on" | "removeListener" | "signMessage">,
|
|
6
|
+
Partial<Omit<UniSatA.Provider, "on" | "removeListener" | "signMessage">> {
|
|
5
7
|
connect?(): Promise<{
|
|
6
8
|
address: string;
|
|
7
9
|
publicKey: string;
|
package/src/btc/index.ts
CHANGED
|
@@ -64,6 +64,14 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
64
64
|
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
65
65
|
*/
|
|
66
66
|
async getBtcAccount(): Promise<string> {
|
|
67
|
+
if (this.provider.getAccounts) {
|
|
68
|
+
const address = (await this.provider.getAccounts())[0];
|
|
69
|
+
if (!address) {
|
|
70
|
+
throw Error("Not connected");
|
|
71
|
+
}
|
|
72
|
+
return address;
|
|
73
|
+
}
|
|
74
|
+
|
|
67
75
|
if (this.provider.getSelectedAccount) {
|
|
68
76
|
const account = await this.provider.getSelectedAccount();
|
|
69
77
|
if (!account) {
|
|
@@ -72,11 +80,7 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
72
80
|
return account.address;
|
|
73
81
|
}
|
|
74
82
|
|
|
75
|
-
|
|
76
|
-
if (!address) {
|
|
77
|
-
throw Error("Not connected");
|
|
78
|
-
}
|
|
79
|
-
return address;
|
|
83
|
+
throw Error("Unsupported OKX provider");
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
/**
|
|
@@ -84,6 +88,10 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
84
88
|
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
85
89
|
*/
|
|
86
90
|
async getBtcPublicKey(): Promise<ccc.Hex> {
|
|
91
|
+
if (this.provider.getPublicKey) {
|
|
92
|
+
return ccc.hexFrom(await this.provider.getPublicKey());
|
|
93
|
+
}
|
|
94
|
+
|
|
87
95
|
if (this.provider.getSelectedAccount) {
|
|
88
96
|
const account = await this.provider.getSelectedAccount();
|
|
89
97
|
if (!account) {
|
|
@@ -92,7 +100,7 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
92
100
|
return ccc.hexFrom(account.compressedPublicKey);
|
|
93
101
|
}
|
|
94
102
|
|
|
95
|
-
|
|
103
|
+
throw Error("Unsupported OKX provider");
|
|
96
104
|
}
|
|
97
105
|
|
|
98
106
|
/**
|
|
@@ -100,11 +108,17 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
100
108
|
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
101
109
|
*/
|
|
102
110
|
async connect(): Promise<void> {
|
|
111
|
+
if (this.provider.requestAccounts) {
|
|
112
|
+
await this.provider.requestAccounts();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
103
116
|
if (this.provider.connect) {
|
|
104
117
|
await this.provider.connect();
|
|
105
118
|
return;
|
|
106
119
|
}
|
|
107
|
-
|
|
120
|
+
|
|
121
|
+
throw Error("Unsupported OKX provider");
|
|
108
122
|
}
|
|
109
123
|
|
|
110
124
|
onReplaced(listener: () => void): () => void {
|
|
@@ -133,12 +147,14 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
133
147
|
return false;
|
|
134
148
|
}
|
|
135
149
|
|
|
136
|
-
if (this.provider.
|
|
150
|
+
if (this.provider.getAccounts) {
|
|
151
|
+
if ((await this.provider.getAccounts()).length === 0) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
} else if (this.provider.getSelectedAccount) {
|
|
137
155
|
if ((await this.provider.getSelectedAccount()) === null) {
|
|
138
156
|
return false;
|
|
139
157
|
}
|
|
140
|
-
} else if ((await this.provider.getAccounts()).length === 0) {
|
|
141
|
-
return false;
|
|
142
158
|
}
|
|
143
159
|
|
|
144
160
|
await this.connect();
|
package/src/nostr/index.ts
CHANGED
|
@@ -18,8 +18,23 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
18
18
|
|
|
19
19
|
async getNostrPublicKey(): Promise<ccc.Hex> {
|
|
20
20
|
if (!this.publicKeyCache) {
|
|
21
|
-
this.publicKeyCache = this.provider
|
|
21
|
+
this.publicKeyCache = this.provider
|
|
22
|
+
.getPublicKey()
|
|
23
|
+
.then((v) => {
|
|
24
|
+
// For some account types of OKX Wallet, this might returns null
|
|
25
|
+
// e.g. Keyless accounts
|
|
26
|
+
if (v) {
|
|
27
|
+
return v;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
throw Error("This OKX Wallet account does not support Nostr");
|
|
31
|
+
})
|
|
32
|
+
.catch((e) => {
|
|
33
|
+
this.publicKeyCache = undefined;
|
|
34
|
+
throw e;
|
|
35
|
+
});
|
|
22
36
|
}
|
|
37
|
+
|
|
23
38
|
return ccc.hexFrom(await this.publicKeyCache);
|
|
24
39
|
}
|
|
25
40
|
|
|
@@ -34,6 +49,8 @@ export class NostrSigner extends ccc.SignerNostr {
|
|
|
34
49
|
|
|
35
50
|
async connect(): Promise<void> {
|
|
36
51
|
await this.provider.connect?.(); // Help extension to switch network
|
|
52
|
+
|
|
53
|
+
await this.getNostrPublicKey();
|
|
37
54
|
}
|
|
38
55
|
|
|
39
56
|
onReplaced(listener: () => void): () => void {
|