@ckb-ccc/okx 0.0.12-alpha.7 → 0.0.13-alpha.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/CHANGELOG.md +20 -0
- package/README.md +10 -7
- package/dist/advancedBarrel.d.ts +0 -1
- package/dist/advancedBarrel.d.ts.map +1 -1
- package/dist/btc/index.d.ts +11 -11
- package/dist/btc/index.d.ts.map +1 -1
- package/dist/btc/index.js +11 -11
- package/dist/nostr/index.d.ts +2 -3
- package/dist/nostr/index.d.ts.map +1 -1
- package/dist/nostr/index.js +2 -3
- package/dist/signersFactory.d.ts +4 -2
- package/dist/signersFactory.d.ts.map +1 -1
- package/dist/signersFactory.js +4 -2
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +19 -40
- package/dist.commonjs/advancedBarrel.d.ts +31 -37
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +14 -30
- package/dist.commonjs/btc/index.d.ts +41 -45
- package/dist.commonjs/btc/index.d.ts.map +1 -1
- package/dist.commonjs/btc/index.js +132 -144
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +19 -40
- package/dist.commonjs/nostr/index.d.ts +11 -12
- package/dist.commonjs/nostr/index.d.ts.map +1 -1
- package/dist.commonjs/nostr/index.js +49 -50
- package/dist.commonjs/signersFactory.d.ts +6 -7
- package/dist.commonjs/signersFactory.d.ts.map +1 -1
- package/dist.commonjs/signersFactory.js +18 -20
- package/package.json +4 -4
- package/src/advancedBarrel.ts +0 -1
- package/src/btc/index.ts +11 -11
- package/src/nostr/index.ts +2 -3
- package/src/signersFactory.ts +4 -2
- package/typedoc.json +6 -0
|
@@ -3,159 +3,147 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BitcoinSigner = void 0;
|
|
4
4
|
const core_1 = require("@ckb-ccc/core");
|
|
5
5
|
/**
|
|
6
|
-
* Class representing a Bitcoin signer that extends SignerBtc
|
|
7
|
-
* @
|
|
8
|
-
* @extends {ccc.SignerBtc}
|
|
6
|
+
* Class representing a Bitcoin signer that extends SignerBtc
|
|
7
|
+
* @public
|
|
9
8
|
*/
|
|
10
9
|
class BitcoinSigner extends core_1.ccc.SignerBtc {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
client,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
);
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of Signer.
|
|
12
|
+
* @param client - The client instance.
|
|
13
|
+
* @param providers - The providers instance.
|
|
14
|
+
* @param preferredNetworks - All preferred networks
|
|
15
|
+
*/
|
|
16
|
+
constructor(client, providers, preferredNetworks = [
|
|
17
|
+
{
|
|
18
|
+
addressPrefix: "ckb",
|
|
19
|
+
signerType: core_1.ccc.SignerType.BTC,
|
|
20
|
+
network: "btc",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
addressPrefix: "ckt",
|
|
24
|
+
signerType: core_1.ccc.SignerType.BTC,
|
|
25
|
+
network: "btcTestnet",
|
|
26
|
+
},
|
|
27
|
+
]) {
|
|
28
|
+
super(client);
|
|
29
|
+
this.providers = providers;
|
|
30
|
+
this.preferredNetworks = preferredNetworks;
|
|
31
|
+
this.network = "btcTestnet";
|
|
52
32
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
33
|
+
get provider() {
|
|
34
|
+
const { network } = this.matchNetworkPreference(this.preferredNetworks, this.network) ?? { network: this.network };
|
|
35
|
+
this.network = network;
|
|
36
|
+
const chain = {
|
|
37
|
+
btc: "bitcoin",
|
|
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;
|
|
58
49
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Gets the Bitcoin account address.
|
|
52
|
+
* @returns A promise that resolves to the Bitcoin account address.
|
|
53
|
+
*/
|
|
54
|
+
async getBtcAccount() {
|
|
55
|
+
if (this.provider.getAccounts) {
|
|
56
|
+
const address = (await this.provider.getAccounts())[0];
|
|
57
|
+
if (!address) {
|
|
58
|
+
throw Error("Not connected");
|
|
59
|
+
}
|
|
60
|
+
return address;
|
|
61
|
+
}
|
|
62
|
+
if (this.provider.getSelectedAccount) {
|
|
63
|
+
const account = await this.provider.getSelectedAccount();
|
|
64
|
+
if (!account) {
|
|
65
|
+
throw Error("Not connected");
|
|
66
|
+
}
|
|
67
|
+
return account.address;
|
|
68
|
+
}
|
|
69
|
+
throw Error("Unsupported OKX provider");
|
|
72
70
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Gets the Bitcoin public key.
|
|
73
|
+
* @returns A promise that resolves to the Bitcoin public key.
|
|
74
|
+
*/
|
|
75
|
+
async getBtcPublicKey() {
|
|
76
|
+
if (this.provider.getPublicKey) {
|
|
77
|
+
return core_1.ccc.hexFrom(await this.provider.getPublicKey());
|
|
78
|
+
}
|
|
79
|
+
if (this.provider.getSelectedAccount) {
|
|
80
|
+
const account = await this.provider.getSelectedAccount();
|
|
81
|
+
if (!account) {
|
|
82
|
+
throw Error("Not connected");
|
|
83
|
+
}
|
|
84
|
+
return core_1.ccc.hexFrom(account.compressedPublicKey);
|
|
85
|
+
}
|
|
86
|
+
throw Error("Unsupported OKX provider");
|
|
79
87
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Connects to the provider by requesting accounts.
|
|
90
|
+
* @returns A promise that resolves when the connection is established.
|
|
91
|
+
*/
|
|
92
|
+
async connect() {
|
|
93
|
+
if (this.provider.requestAccounts) {
|
|
94
|
+
await this.provider.requestAccounts();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (this.provider.connect) {
|
|
98
|
+
await this.provider.connect();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
throw Error("Unsupported OKX provider");
|
|
89
102
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
onReplaced(listener) {
|
|
104
|
+
const stop = [];
|
|
105
|
+
const replacer = async () => {
|
|
106
|
+
listener();
|
|
107
|
+
stop[0]?.();
|
|
108
|
+
};
|
|
109
|
+
stop.push(() => {
|
|
110
|
+
this.provider.removeListener("accountChanged", replacer);
|
|
111
|
+
});
|
|
112
|
+
this.provider.on("accountChanged", replacer);
|
|
113
|
+
return stop[0];
|
|
96
114
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Checks if the signer is connected.
|
|
117
|
+
* @returns A promise that resolves to true if connected, false otherwise.
|
|
118
|
+
*/
|
|
119
|
+
async isConnected() {
|
|
120
|
+
try {
|
|
121
|
+
this.provider;
|
|
122
|
+
}
|
|
123
|
+
catch (_) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
if (this.provider.getAccounts) {
|
|
127
|
+
if ((await this.provider.getAccounts()).length === 0) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else if (this.provider.getSelectedAccount) {
|
|
132
|
+
if ((await this.provider.getSelectedAccount()) === null) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
await this.connect();
|
|
137
|
+
return true;
|
|
107
138
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
139
|
+
/**
|
|
140
|
+
* Signs a raw message with the Bitcoin account.
|
|
141
|
+
* @param message - The message to sign.
|
|
142
|
+
* @returns A promise that resolves to the signed message.
|
|
143
|
+
*/
|
|
144
|
+
async signMessageRaw(message) {
|
|
145
|
+
const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
|
|
146
|
+
return this.provider.signMessage(challenge, "ecdsa");
|
|
111
147
|
}
|
|
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
|
-
}
|
|
160
148
|
}
|
|
161
149
|
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,48 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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) {
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
37
19
|
if (mod && mod.__esModule) return mod;
|
|
38
20
|
var result = {};
|
|
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);
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
43
22
|
__setModuleDefault(result, mod);
|
|
44
23
|
return result;
|
|
45
|
-
|
|
24
|
+
};
|
|
46
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
26
|
exports.Okx = void 0;
|
|
48
27
|
exports.Okx = __importStar(require("./barrel.js"));
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { NostrProvider } from "../advancedBarrel.js";
|
|
3
3
|
/**
|
|
4
|
-
* Class representing a Bitcoin signer that extends SignerBtc
|
|
5
|
-
* @
|
|
6
|
-
* @extends {ccc.SignerBtc}
|
|
4
|
+
* Class representing a Bitcoin signer that extends SignerBtc
|
|
5
|
+
* @public
|
|
7
6
|
*/
|
|
8
7
|
export declare class NostrSigner extends ccc.SignerNostr {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
readonly provider: NostrProvider;
|
|
9
|
+
private publicKeyCache?;
|
|
10
|
+
constructor(client: ccc.Client, provider: NostrProvider);
|
|
11
|
+
getNostrPublicKey(): Promise<ccc.Hex>;
|
|
12
|
+
signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
|
|
13
|
+
connect(): Promise<void>;
|
|
14
|
+
onReplaced(listener: () => void): () => void;
|
|
15
|
+
isConnected(): Promise<boolean>;
|
|
17
16
|
}
|
|
18
|
-
//# sourceMappingURL=index.d.ts.map
|
|
17
|
+
//# 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
|
|
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;;;GAGG;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"}
|
|
@@ -3,59 +3,58 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.NostrSigner = void 0;
|
|
4
4
|
const core_1 = require("@ckb-ccc/core");
|
|
5
5
|
/**
|
|
6
|
-
* Class representing a Bitcoin signer that extends SignerBtc
|
|
7
|
-
* @
|
|
8
|
-
* @extends {ccc.SignerBtc}
|
|
6
|
+
* Class representing a Bitcoin signer that extends SignerBtc
|
|
7
|
+
* @public
|
|
9
8
|
*/
|
|
10
9
|
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
|
-
|
|
10
|
+
constructor(client, provider) {
|
|
11
|
+
super(client);
|
|
12
|
+
this.provider = provider;
|
|
13
|
+
this.publicKeyCache = undefined;
|
|
14
|
+
}
|
|
15
|
+
async getNostrPublicKey() {
|
|
16
|
+
if (!this.publicKeyCache) {
|
|
17
|
+
this.publicKeyCache = this.provider
|
|
18
|
+
.getPublicKey()
|
|
19
|
+
.then((v) => {
|
|
20
|
+
// For some account types of OKX Wallet, this might returns null
|
|
21
|
+
// e.g. Keyless accounts
|
|
22
|
+
if (v) {
|
|
23
|
+
return v;
|
|
24
|
+
}
|
|
25
|
+
throw Error("This OKX Wallet account does not support Nostr");
|
|
26
|
+
})
|
|
27
|
+
.catch((e) => {
|
|
28
|
+
this.publicKeyCache = undefined;
|
|
29
|
+
throw e;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return core_1.ccc.hexFrom(await this.publicKeyCache);
|
|
33
|
+
}
|
|
34
|
+
async signNostrEvent(event) {
|
|
35
|
+
return this.provider.signEvent({
|
|
36
|
+
...event,
|
|
37
|
+
pubkey: await this.publicKeyCache,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async connect() {
|
|
41
|
+
await this.provider.connect?.(); // Help extension to switch network
|
|
42
|
+
await this.getNostrPublicKey();
|
|
43
|
+
}
|
|
44
|
+
onReplaced(listener) {
|
|
45
|
+
const stop = [];
|
|
46
|
+
const replacer = async () => {
|
|
47
|
+
listener();
|
|
48
|
+
stop[0]?.();
|
|
49
|
+
};
|
|
50
|
+
stop.push(() => {
|
|
51
|
+
this.provider.removeListener("accountChanged", replacer);
|
|
31
52
|
});
|
|
53
|
+
this.provider.on("accountChanged", replacer);
|
|
54
|
+
return stop[0];
|
|
55
|
+
}
|
|
56
|
+
async isConnected() {
|
|
57
|
+
return true;
|
|
32
58
|
}
|
|
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
|
-
}
|
|
60
59
|
}
|
|
61
60
|
exports.NostrSigner = NostrSigner;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves the OKX Bitcoin signer if available.
|
|
4
|
-
* @
|
|
5
|
-
*
|
|
4
|
+
* @public
|
|
5
|
+
*
|
|
6
|
+
* @param client - The client instance.
|
|
7
|
+
* @returns The BitcoinSigner instance if the OKX wallet is available, otherwise undefined.
|
|
6
8
|
*/
|
|
7
|
-
export declare function getOKXSigners(
|
|
8
|
-
|
|
9
|
-
preferredNetworks?: ccc.NetworkPreference[],
|
|
10
|
-
): ccc.SignerInfo[];
|
|
11
|
-
//# sourceMappingURL=signersFactory.d.ts.map
|
|
9
|
+
export declare function getOKXSigners(client: ccc.Client, preferredNetworks?: ccc.NetworkPreference[]): ccc.SignerInfo[];
|
|
10
|
+
//# sourceMappingURL=signersFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAKpC
|
|
1
|
+
{"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAKpC;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,iBAAiB,CAAC,EAAE,GAAG,CAAC,iBAAiB,EAAE,GAC1C,GAAG,CAAC,UAAU,EAAE,CAmBlB"}
|
|
@@ -5,27 +5,25 @@ const index_js_1 = require("./btc/index.js");
|
|
|
5
5
|
const index_js_2 = require("./nostr/index.js");
|
|
6
6
|
/**
|
|
7
7
|
* Retrieves the OKX Bitcoin signer if available.
|
|
8
|
-
* @
|
|
9
|
-
*
|
|
8
|
+
* @public
|
|
9
|
+
*
|
|
10
|
+
* @param client - The client instance.
|
|
11
|
+
* @returns The BitcoinSigner instance if the OKX wallet is available, otherwise undefined.
|
|
10
12
|
*/
|
|
11
13
|
function getOKXSigners(client, preferredNetworks) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
signer: new index_js_2.NostrSigner(client, windowRef.okxwallet.nostr),
|
|
27
|
-
name: "Nostr",
|
|
28
|
-
},
|
|
29
|
-
];
|
|
14
|
+
const windowRef = window;
|
|
15
|
+
if (typeof windowRef.okxwallet === "undefined") {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
return [
|
|
19
|
+
{
|
|
20
|
+
signer: new index_js_1.BitcoinSigner(client, windowRef.okxwallet, preferredNetworks),
|
|
21
|
+
name: "BTC",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
signer: new index_js_2.NostrSigner(client, windowRef.okxwallet.nostr),
|
|
25
|
+
name: "Nostr",
|
|
26
|
+
},
|
|
27
|
+
];
|
|
30
28
|
}
|
|
31
29
|
exports.getOKXSigners = getOKXSigners;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/okx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13-alpha.0",
|
|
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",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@ckb-ccc/core": "0.0.
|
|
42
|
-
"@ckb-ccc/
|
|
43
|
-
"@ckb-ccc/
|
|
41
|
+
"@ckb-ccc/core": "0.0.13-alpha.0",
|
|
42
|
+
"@ckb-ccc/uni-sat": "0.0.13-alpha.0",
|
|
43
|
+
"@ckb-ccc/nip07": "0.0.13-alpha.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
|