@ckb-ccc/okx 0.0.10-alpha.4 → 0.0.10-alpha.5
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.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +19 -40
- package/dist.commonjs/advancedBarrel.d.ts +30 -33
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +14 -30
- package/dist.commonjs/btc/index.d.ts +38 -42
- package/dist.commonjs/btc/index.js +117 -129
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +19 -40
- package/dist.commonjs/nostr/index.d.ts +9 -9
- package/dist.commonjs/nostr/index.js +34 -34
- package/dist.commonjs/signersFactory.d.ts +2 -5
- package/dist.commonjs/signersFactory.js +8 -8
- package/package.json +5 -5
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * as OkxA from "./advancedBarrel";
|
|
2
|
-
//# sourceMappingURL=advanced.d.ts.map
|
|
2
|
+
//# sourceMappingURL=advanced.d.ts.map
|
|
@@ -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.OkxA = void 0;
|
|
48
27
|
exports.OkxA = __importStar(require("./advancedBarrel"));
|
|
@@ -1,45 +1,42 @@
|
|
|
1
1
|
import { Nip07A } from "@ckb-ccc/nip07/advanced";
|
|
2
2
|
import { UniSatA } from "@ckb-ccc/uni-sat/advanced";
|
|
3
3
|
export interface BitcoinProvider extends UniSatA.Provider {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
connect?(): Promise<{
|
|
5
|
+
address: string;
|
|
6
|
+
publicKey: string;
|
|
7
|
+
compressedPublicKey: string;
|
|
8
|
+
}>;
|
|
9
|
+
getSelectedAccount?(): Promise<{
|
|
10
|
+
address: string;
|
|
11
|
+
publicKey: string;
|
|
12
|
+
compressedPublicKey: string;
|
|
13
|
+
} | null>;
|
|
14
14
|
}
|
|
15
15
|
export interface NostrProvider extends Nip07A.Provider {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
eventName: string,
|
|
29
|
-
listener: (...args: unknown[]) => unknown,
|
|
30
|
-
): NostrProvider;
|
|
16
|
+
connect?(): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Adds an event listener to the provider.
|
|
19
|
+
*/
|
|
20
|
+
on: NostrOnMethod;
|
|
21
|
+
/**
|
|
22
|
+
* Removes an event listener from the provider.
|
|
23
|
+
* @param eventName - The name of the event to remove the listener from.
|
|
24
|
+
* @param listener - The listener function to remove.
|
|
25
|
+
* @returns The provider instance.
|
|
26
|
+
*/
|
|
27
|
+
removeListener(eventName: string, listener: (...args: unknown[]) => unknown): NostrProvider;
|
|
31
28
|
}
|
|
32
29
|
/**
|
|
33
30
|
* Interface representing a method to add event listeners to the provider.
|
|
34
31
|
* @interface
|
|
35
32
|
*/
|
|
36
33
|
export interface NostrOnMethod {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Adds an event listener to the provider.
|
|
36
|
+
* @param eventName - The name of the event.
|
|
37
|
+
* @param listener - The listener function.
|
|
38
|
+
* @returns The provider instance.
|
|
39
|
+
*/
|
|
40
|
+
(eventName: string, listener: (...args: unknown[]) => unknown): Promise<void>;
|
|
44
41
|
}
|
|
45
|
-
//# sourceMappingURL=advancedBarrel.d.ts.map
|
|
42
|
+
//# sourceMappingURL=advancedBarrel.d.ts.map
|
package/dist.commonjs/barrel.js
CHANGED
|
@@ -1,34 +1,18 @@
|
|
|
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 __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
|
-
};
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
32
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
17
|
__exportStar(require("./btc"), exports);
|
|
34
18
|
__exportStar(require("./signersFactory"), exports);
|
|
@@ -6,46 +6,42 @@ import { BitcoinProvider } from "../advancedBarrel";
|
|
|
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
|
-
|
|
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>;
|
|
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(client: ccc.Client, providers: Record<string, BitcoinProvider>, preferredNetworks?: ccc.NetworkPreference[]);
|
|
18
|
+
get provider(): BitcoinProvider;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the Bitcoin account address.
|
|
21
|
+
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
22
|
+
*/
|
|
23
|
+
getBtcAccount(): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Gets the Bitcoin public key.
|
|
26
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
27
|
+
*/
|
|
28
|
+
getBtcPublicKey(): Promise<ccc.Hex>;
|
|
29
|
+
/**
|
|
30
|
+
* Connects to the provider by requesting accounts.
|
|
31
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
32
|
+
*/
|
|
33
|
+
connect(): Promise<void>;
|
|
34
|
+
onReplaced(listener: () => void): () => void;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if the signer is connected.
|
|
37
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
38
|
+
*/
|
|
39
|
+
isConnected(): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Signs a raw message with the Bitcoin account.
|
|
42
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
43
|
+
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
44
|
+
*/
|
|
45
|
+
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
50
46
|
}
|
|
51
|
-
//# sourceMappingURL=index.d.ts.map
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -8,142 +8,130 @@ 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
|
-
|
|
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
|
-
);
|
|
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(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 {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
53
|
+
*/
|
|
54
|
+
async getBtcAccount() {
|
|
55
|
+
if (this.provider.getSelectedAccount) {
|
|
56
|
+
const account = await this.provider.getSelectedAccount();
|
|
57
|
+
if (!account) {
|
|
58
|
+
throw Error("Not connected");
|
|
59
|
+
}
|
|
60
|
+
return account.address;
|
|
61
|
+
}
|
|
62
|
+
const address = (await this.provider.getAccounts())[0];
|
|
63
|
+
if (!address) {
|
|
64
|
+
throw Error("Not connected");
|
|
65
|
+
}
|
|
66
|
+
return address;
|
|
72
67
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Gets the Bitcoin public key.
|
|
70
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
71
|
+
*/
|
|
72
|
+
async getBtcPublicKey() {
|
|
73
|
+
if (this.provider.getSelectedAccount) {
|
|
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());
|
|
76
81
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
throw Error("Not connected");
|
|
88
|
-
}
|
|
89
|
-
return core_1.ccc.hexFrom(account.compressedPublicKey);
|
|
82
|
+
/**
|
|
83
|
+
* Connects to the provider by requesting accounts.
|
|
84
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
85
|
+
*/
|
|
86
|
+
async connect() {
|
|
87
|
+
if (this.provider.connect) {
|
|
88
|
+
await this.provider.connect();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
await this.provider.requestAccounts();
|
|
90
92
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
onReplaced(listener) {
|
|
94
|
+
const stop = [];
|
|
95
|
+
const replacer = async () => {
|
|
96
|
+
listener();
|
|
97
|
+
stop[0]?.();
|
|
98
|
+
};
|
|
99
|
+
stop.push(() => {
|
|
100
|
+
this.provider.removeListener("accountChanged", replacer);
|
|
101
|
+
});
|
|
102
|
+
this.provider.on("accountChanged", replacer);
|
|
103
|
+
return stop[0];
|
|
101
104
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
} catch (_) {
|
|
124
|
-
return false;
|
|
105
|
+
/**
|
|
106
|
+
* Checks if the signer is connected.
|
|
107
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
108
|
+
*/
|
|
109
|
+
async isConnected() {
|
|
110
|
+
try {
|
|
111
|
+
this.provider;
|
|
112
|
+
}
|
|
113
|
+
catch (_) {
|
|
114
|
+
return false;
|
|
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;
|
|
125
126
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Signs a raw message with the Bitcoin account.
|
|
129
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
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");
|
|
132
135
|
}
|
|
133
|
-
await this.connect();
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Signs a raw message with the Bitcoin account.
|
|
138
|
-
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
139
|
-
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
140
|
-
*/
|
|
141
|
-
async signMessageRaw(message) {
|
|
142
|
-
const challenge =
|
|
143
|
-
typeof message === "string"
|
|
144
|
-
? message
|
|
145
|
-
: core_1.ccc.hexFrom(message).slice(2);
|
|
146
|
-
return this.provider.signMessage(challenge, "ecdsa");
|
|
147
|
-
}
|
|
148
136
|
}
|
|
149
137
|
exports.BitcoinSigner = BitcoinSigner;
|
package/dist.commonjs/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * as Okx from "./barrel";
|
|
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"));
|
|
@@ -6,13 +6,13 @@ import { NostrProvider } from "../advancedBarrel";
|
|
|
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
|
|
@@ -8,40 +8,40 @@ 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
|
-
|
|
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.getPublicKey();
|
|
19
|
+
}
|
|
20
|
+
return core_1.ccc.hexFrom(await this.publicKeyCache);
|
|
21
|
+
}
|
|
22
|
+
async signNostrEvent(event) {
|
|
23
|
+
return this.provider.signEvent({
|
|
24
|
+
...event,
|
|
25
|
+
pubkey: await this.publicKeyCache,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async connect() {
|
|
29
|
+
await this.provider.connect?.(); // Help extension to switch network
|
|
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);
|
|
39
|
+
});
|
|
40
|
+
this.provider.on("accountChanged", replacer);
|
|
41
|
+
return stop[0];
|
|
42
|
+
}
|
|
43
|
+
async isConnected() {
|
|
44
|
+
return true;
|
|
19
45
|
}
|
|
20
|
-
return core_1.ccc.hexFrom(await this.publicKeyCache);
|
|
21
|
-
}
|
|
22
|
-
async signNostrEvent(event) {
|
|
23
|
-
return this.provider.signEvent({
|
|
24
|
-
...event,
|
|
25
|
-
pubkey: await this.publicKeyCache,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
async connect() {
|
|
29
|
-
await this.provider.connect?.(); // Help extension to switch network
|
|
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);
|
|
39
|
-
});
|
|
40
|
-
this.provider.on("accountChanged", replacer);
|
|
41
|
-
return stop[0];
|
|
42
|
-
}
|
|
43
|
-
async isConnected() {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
46
|
}
|
|
47
47
|
exports.NostrSigner = NostrSigner;
|
|
@@ -4,8 +4,5 @@ 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 getOKXBitcoinSigner(
|
|
8
|
-
|
|
9
|
-
preferredNetworks: ccc.NetworkPreference[],
|
|
10
|
-
): ccc.Signer[];
|
|
11
|
-
//# sourceMappingURL=signersFactory.d.ts.map
|
|
7
|
+
export declare function getOKXBitcoinSigner(client: ccc.Client, preferredNetworks: ccc.NetworkPreference[]): ccc.Signer[];
|
|
8
|
+
//# sourceMappingURL=signersFactory.d.ts.map
|
|
@@ -9,13 +9,13 @@ const nostr_1 = require("./nostr");
|
|
|
9
9
|
* @returns {BitcoinSigner | undefined} The BitcoinSigner instance if the OKX wallet is available, otherwise undefined.
|
|
10
10
|
*/
|
|
11
11
|
function getOKXBitcoinSigner(client, preferredNetworks) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
const windowRef = window;
|
|
13
|
+
if (typeof windowRef.okxwallet === "undefined") {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
return [
|
|
17
|
+
new btc_1.BitcoinSigner(client, windowRef.okxwallet, preferredNetworks),
|
|
18
|
+
new nostr_1.NostrSigner(client, windowRef.okxwallet.nostr),
|
|
19
|
+
];
|
|
20
20
|
}
|
|
21
21
|
exports.getOKXBitcoinSigner = getOKXBitcoinSigner;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/okx",
|
|
3
|
-
"version": "0.0.10-alpha.
|
|
3
|
+
"version": "0.0.10-alpha.5",
|
|
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",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ckb-ccc/core": "0.0.10-alpha.
|
|
46
|
-
"@ckb-ccc/nip07": "0.0.10-alpha.
|
|
47
|
-
"@ckb-ccc/uni-sat": "0.0.10-alpha.
|
|
45
|
+
"@ckb-ccc/core": "0.0.10-alpha.5",
|
|
46
|
+
"@ckb-ccc/nip07": "0.0.10-alpha.5",
|
|
47
|
+
"@ckb-ccc/uni-sat": "0.0.10-alpha.5"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "40a3d50aa3697a98c7ac711cd526ef322ccad760"
|
|
50
50
|
}
|