@ckb-ccc/core 0.0.5-alpha.0 → 0.0.5-alpha.10
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/address/index.d.ts +1 -1
- package/dist/address/index.d.ts.map +1 -1
- package/dist/address/index.js +4 -4
- package/dist/ckb/transaction.d.ts +2 -2
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +2 -3
- package/dist/client/client.d.ts +6 -3
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +16 -0
- package/dist/client/clientPublicMainnet.d.ts +1 -1
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.js +1 -1
- package/dist/client/clientPublicTestnet.d.ts +1 -1
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.js +1 -1
- package/dist/client/jsonRpc/index.d.ts +15 -5
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +16 -6
- package/dist/signer/btc/index.d.ts +1 -0
- package/dist/signer/btc/index.d.ts.map +1 -1
- package/dist/signer/btc/index.js +1 -0
- package/dist/signer/btc/signerBtc.d.ts +9 -1
- package/dist/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist/signer/btc/signerBtc.js +19 -3
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +0 -6
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
- package/dist/signer/btc/signerBtcPublicKeyReadonly.js +0 -8
- package/dist/signer/btc/verify.d.ts +3 -0
- package/dist/signer/btc/verify.d.ts.map +1 -0
- package/dist/signer/btc/verify.js +6 -0
- package/dist/signer/ckb/index.d.ts +1 -0
- package/dist/signer/ckb/index.d.ts.map +1 -1
- package/dist/signer/ckb/index.js +1 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +3 -7
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
- package/dist/signer/ckb/signerCkbScriptReadonly.js +8 -10
- package/dist/signer/ckb/verifyJoyId.d.ts +3 -0
- package/dist/signer/ckb/verifyJoyId.d.ts.map +1 -0
- package/dist/signer/ckb/verifyJoyId.js +12 -0
- package/dist/signer/dummy/alwaysError.d.ts +9 -0
- package/dist/signer/dummy/alwaysError.d.ts.map +1 -0
- package/dist/signer/dummy/alwaysError.js +10 -0
- package/dist/signer/dummy/dummy.d.ts +12 -0
- package/dist/signer/dummy/dummy.d.ts.map +1 -0
- package/dist/signer/dummy/dummy.js +19 -0
- package/dist/signer/dummy/index.d.ts +4 -0
- package/dist/signer/dummy/index.d.ts.map +1 -0
- package/dist/signer/dummy/index.js +3 -0
- package/dist/signer/dummy/openLink.d.ts +9 -0
- package/dist/signer/dummy/openLink.d.ts.map +1 -0
- package/dist/signer/dummy/openLink.js +10 -0
- package/dist/signer/evm/index.d.ts +1 -0
- package/dist/signer/evm/index.d.ts.map +1 -1
- package/dist/signer/evm/index.js +1 -0
- package/dist/signer/evm/signerEvm.d.ts +3 -1
- package/dist/signer/evm/signerEvm.d.ts.map +1 -1
- package/dist/signer/evm/signerEvm.js +10 -4
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts +0 -6
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
- package/dist/signer/evm/signerEvmAddressReadonly.js +0 -8
- package/dist/signer/evm/verify.d.ts +3 -0
- package/dist/signer/evm/verify.d.ts.map +1 -0
- package/dist/signer/evm/verify.js +6 -0
- package/dist/signer/index.d.ts +1 -0
- package/dist/signer/index.d.ts.map +1 -1
- package/dist/signer/index.js +1 -0
- package/{dist.commonjs/signer/signer.d.ts → dist/signer/signer/index.d.ts} +75 -24
- package/dist/signer/signer/index.d.ts.map +1 -0
- package/dist/signer/signer/index.js +205 -0
- package/dist/utils/index.d.ts +60 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +20 -0
- package/dist.commonjs/address/address.advanced.d.ts +29 -24
- package/dist.commonjs/address/address.advanced.js +114 -92
- package/dist.commonjs/address/advanced.d.ts +1 -1
- package/dist.commonjs/address/advanced.js +30 -14
- package/dist.commonjs/address/index.d.ts +51 -44
- package/dist.commonjs/address/index.d.ts.map +1 -1
- package/dist.commonjs/address/index.js +87 -68
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +47 -22
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +30 -14
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +30 -14
- package/dist.commonjs/bytes/advanced.d.ts +11 -2
- package/dist.commonjs/bytes/index.d.ts +9 -3
- package/dist.commonjs/bytes/index.js +28 -26
- package/dist.commonjs/ckb/advanced.d.ts +1 -1
- package/dist.commonjs/ckb/advanced.js +47 -22
- package/dist.commonjs/ckb/index.d.ts +1 -1
- package/dist.commonjs/ckb/index.js +30 -14
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +420 -260
- package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -1332
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
- package/dist.commonjs/ckb/molecule.advanced/index.js +34 -18
- package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
- package/dist.commonjs/ckb/script.advanced.js +12 -9
- package/dist.commonjs/ckb/script.d.ts +76 -76
- package/dist.commonjs/ckb/script.js +166 -126
- package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
- package/dist.commonjs/ckb/transaction.advanced.js +4 -4
- package/dist.commonjs/ckb/transaction.d.ts +570 -532
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +839 -723
- package/dist.commonjs/client/advanced.d.ts +1 -1
- package/dist.commonjs/client/advanced.js +30 -14
- package/dist.commonjs/client/client.d.ts +53 -19
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +68 -43
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +5 -2
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +30 -24
- package/dist.commonjs/client/clientPublicMainnet.d.ts +6 -4
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.js +9 -9
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +5 -2
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +30 -24
- package/dist.commonjs/client/clientPublicTestnet.d.ts +6 -4
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.js +9 -9
- package/dist.commonjs/client/clientTypes.d.ts +51 -36
- package/dist.commonjs/client/clientTypes.js +34 -19
- package/dist.commonjs/client/index.d.ts +1 -1
- package/dist.commonjs/client/index.js +30 -14
- package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
- package/dist.commonjs/client/jsonRpc/advanced.js +30 -14
- package/dist.commonjs/client/jsonRpc/index.d.ts +93 -66
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +135 -98
- package/dist.commonjs/client/jsonRpc/transformers.d.ts +78 -38
- package/dist.commonjs/client/jsonRpc/transformers.js +175 -150
- package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
- package/dist.commonjs/fixedPoint/index.d.ts +9 -3
- package/dist.commonjs/fixedPoint/index.js +26 -20
- package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
- package/dist.commonjs/fixedPoint/index.test.js +42 -36
- package/dist.commonjs/hasher/advanced.d.ts +1 -1
- package/dist.commonjs/hasher/index.d.ts +36 -36
- package/dist.commonjs/hasher/index.js +52 -45
- package/dist.commonjs/hex/index.d.ts +1 -1
- package/dist.commonjs/hex/index.js +1 -1
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +47 -22
- package/dist.commonjs/num/index.d.ts +1 -1
- package/dist.commonjs/num/index.js +30 -19
- package/dist.commonjs/signer/btc/index.d.ts +2 -1
- package/dist.commonjs/signer/btc/index.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/index.js +31 -14
- package/dist.commonjs/signer/btc/signerBtc.d.ts +48 -40
- package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/signerBtc.js +85 -49
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -51
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -60
- package/dist.commonjs/signer/btc/verify.d.ts +7 -0
- package/dist.commonjs/signer/btc/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/btc/verify.js +13 -0
- package/dist.commonjs/signer/ckb/index.d.ts +2 -1
- package/dist.commonjs/signer/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/signer/ckb/index.js +31 -14
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +46 -50
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -58
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +7 -0
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/verifyJoyId.js +19 -0
- package/dist.commonjs/signer/dummy/alwaysError.d.ts +9 -0
- package/dist.commonjs/signer/dummy/alwaysError.d.ts.map +1 -0
- package/dist.commonjs/signer/dummy/alwaysError.js +14 -0
- package/dist.commonjs/signer/dummy/dummy.d.ts +12 -0
- package/dist.commonjs/signer/dummy/dummy.d.ts.map +1 -0
- package/dist.commonjs/signer/dummy/dummy.js +23 -0
- package/dist.commonjs/signer/dummy/index.d.ts +4 -0
- package/dist.commonjs/signer/dummy/index.d.ts.map +1 -0
- package/dist.commonjs/signer/dummy/index.js +35 -0
- package/dist.commonjs/signer/dummy/openLink.d.ts +9 -0
- package/dist.commonjs/signer/dummy/openLink.d.ts.map +1 -0
- package/dist.commonjs/signer/dummy/openLink.js +14 -0
- package/dist.commonjs/signer/evm/index.d.ts +2 -1
- package/dist.commonjs/signer/evm/index.d.ts.map +1 -1
- package/dist.commonjs/signer/evm/index.js +31 -14
- package/dist.commonjs/signer/evm/signerEvm.d.ts +43 -37
- package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
- package/dist.commonjs/signer/evm/signerEvm.js +101 -63
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -43
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -50
- package/dist.commonjs/signer/evm/verify.d.ts +7 -0
- package/dist.commonjs/signer/evm/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/evm/verify.js +15 -0
- package/dist.commonjs/signer/index.d.ts +2 -1
- package/dist.commonjs/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/index.js +31 -14
- package/dist.commonjs/signer/signer/index.d.ts +190 -0
- package/dist.commonjs/signer/signer/index.d.ts.map +1 -0
- package/dist.commonjs/signer/signer/index.js +234 -0
- package/dist.commonjs/utils/index.d.ts +94 -6
- package/dist.commonjs/utils/index.d.ts.map +1 -1
- package/dist.commonjs/utils/index.js +33 -5
- package/package.json +6 -3
- package/src/address/index.ts +4 -7
- package/src/ckb/transaction.ts +4 -5
- package/src/client/client.ts +27 -3
- package/src/client/clientPublicMainnet.ts +1 -1
- package/src/client/clientPublicTestnet.ts +1 -1
- package/src/client/jsonRpc/index.ts +21 -5
- package/src/signer/btc/index.ts +1 -0
- package/src/signer/btc/signerBtc.ts +22 -7
- package/src/signer/btc/signerBtcPublicKeyReadonly.ts +0 -9
- package/src/signer/btc/verify.ts +14 -0
- package/src/signer/ckb/index.ts +1 -0
- package/src/signer/ckb/signerCkbScriptReadonly.ts +10 -11
- package/src/signer/ckb/verifyJoyId.ts +20 -0
- package/src/signer/dummy/alwaysError.ts +17 -0
- package/src/signer/dummy/dummy.ts +28 -0
- package/src/signer/dummy/index.ts +3 -0
- package/src/signer/dummy/openLink.ts +17 -0
- package/src/signer/evm/index.ts +1 -0
- package/src/signer/evm/signerEvm.ts +16 -10
- package/src/signer/evm/signerEvmAddressReadonly.ts +0 -9
- package/src/signer/evm/verify.ts +16 -0
- package/src/signer/index.ts +1 -0
- package/src/signer/{signer.ts → signer/index.ts} +146 -24
- package/src/utils/index.ts +108 -0
- package/dist/signer/signer.d.ts +0 -133
- package/dist/signer/signer.d.ts.map +0 -1
- package/dist/signer/signer.js +0 -112
- package/dist.commonjs/signer/signer.d.ts.map +0 -1
- package/dist.commonjs/signer/signer.js +0 -117
- package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +0 -1
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerInfo =
|
|
4
|
+
exports.Signer =
|
|
5
|
+
exports.Signature =
|
|
6
|
+
exports.SignerType =
|
|
7
|
+
exports.SignerSignType =
|
|
8
|
+
void 0;
|
|
9
|
+
const btc_1 = require("../btc");
|
|
10
|
+
const verifyJoyId_1 = require("../ckb/verifyJoyId");
|
|
11
|
+
const verify_1 = require("../evm/verify");
|
|
12
|
+
var SignerSignType;
|
|
13
|
+
(function (SignerSignType) {
|
|
14
|
+
SignerSignType["Unknown"] = "Unknown";
|
|
15
|
+
SignerSignType["BtcEcdsa"] = "BtcEcdsa";
|
|
16
|
+
SignerSignType["EvmPersonal"] = "EvmPersonal";
|
|
17
|
+
SignerSignType["JoyId"] = "JoyId";
|
|
18
|
+
})(SignerSignType || (exports.SignerSignType = SignerSignType = {}));
|
|
19
|
+
/**
|
|
20
|
+
* An enumeration of signer display types in wallet.
|
|
21
|
+
*/
|
|
22
|
+
var SignerType;
|
|
23
|
+
(function (SignerType) {
|
|
24
|
+
SignerType["EVM"] = "EVM";
|
|
25
|
+
SignerType["BTC"] = "BTC";
|
|
26
|
+
SignerType["CKB"] = "CKB";
|
|
27
|
+
})(SignerType || (exports.SignerType = SignerType = {}));
|
|
28
|
+
class Signature {
|
|
29
|
+
constructor(signature, identity, signType) {
|
|
30
|
+
this.signature = signature;
|
|
31
|
+
this.identity = identity;
|
|
32
|
+
this.signType = signType;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Signature = Signature;
|
|
36
|
+
/**
|
|
37
|
+
* An abstract class representing a generic signer.
|
|
38
|
+
* This class provides methods to connect, get addresses, and sign transactions.
|
|
39
|
+
*/
|
|
40
|
+
class Signer {
|
|
41
|
+
constructor(client_) {
|
|
42
|
+
this.client_ = client_;
|
|
43
|
+
}
|
|
44
|
+
get client() {
|
|
45
|
+
return this.client_;
|
|
46
|
+
}
|
|
47
|
+
static async verifyMessage(message, signature) {
|
|
48
|
+
switch (signature.signType) {
|
|
49
|
+
case SignerSignType.EvmPersonal:
|
|
50
|
+
return (0, verify_1.verifyMessageEvmPersonal)(
|
|
51
|
+
message,
|
|
52
|
+
signature.signature,
|
|
53
|
+
signature.identity,
|
|
54
|
+
);
|
|
55
|
+
case SignerSignType.BtcEcdsa:
|
|
56
|
+
return (0, btc_1.verifyMessageBtcEcdsa)(
|
|
57
|
+
message,
|
|
58
|
+
signature.signature,
|
|
59
|
+
signature.identity,
|
|
60
|
+
);
|
|
61
|
+
case SignerSignType.JoyId:
|
|
62
|
+
return (0, verifyJoyId_1.verifyMessageJoyId)(
|
|
63
|
+
message,
|
|
64
|
+
signature.signature,
|
|
65
|
+
signature.identity,
|
|
66
|
+
);
|
|
67
|
+
case SignerSignType.Unknown:
|
|
68
|
+
throw new Error("Unknown signer sign type");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Replace the current client.
|
|
73
|
+
*/
|
|
74
|
+
async replaceClient(client) {
|
|
75
|
+
this.client_ = client;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Disconnects to the signer.
|
|
79
|
+
*
|
|
80
|
+
* @returns A promise that resolves when disconnected.
|
|
81
|
+
*/
|
|
82
|
+
async disconnect() {}
|
|
83
|
+
/**
|
|
84
|
+
* Gets the identity for verifying signature, usually it's address
|
|
85
|
+
*
|
|
86
|
+
* @returns A promise that resolves to a string representing the identity
|
|
87
|
+
*/
|
|
88
|
+
async getIdentity() {
|
|
89
|
+
return this.getInternalAddress();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Gets the recommended Address object for the signer.
|
|
93
|
+
*
|
|
94
|
+
* @param _preference - Optional preference parameter.
|
|
95
|
+
* @returns A promise that resolves to the recommended Address object.
|
|
96
|
+
*/
|
|
97
|
+
async getRecommendedAddressObj(_preference) {
|
|
98
|
+
return (await this.getAddressObjs())[0];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Gets the recommended address for the signer as a string.
|
|
102
|
+
*
|
|
103
|
+
* @param preference - Optional preference parameter.
|
|
104
|
+
* @returns A promise that resolves to the recommended address as a string.
|
|
105
|
+
*/
|
|
106
|
+
async getRecommendedAddress(preference) {
|
|
107
|
+
return (await this.getRecommendedAddressObj(preference)).toString();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Gets an array of addresses associated with the signer as strings.
|
|
111
|
+
*
|
|
112
|
+
* @returns A promise that resolves to an array of addresses as strings.
|
|
113
|
+
*/
|
|
114
|
+
async getAddresses() {
|
|
115
|
+
return this.getAddressObjs().then((addresses) =>
|
|
116
|
+
addresses.map((address) => address.toString()),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Gets balance of all addresses
|
|
121
|
+
*
|
|
122
|
+
* @returns A promise that resolves to the balance
|
|
123
|
+
*/
|
|
124
|
+
async getBalance() {
|
|
125
|
+
return this.client.getBalance(
|
|
126
|
+
(await this.getAddressObjs()).map(({ script }) => script),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Signs a message.
|
|
131
|
+
*
|
|
132
|
+
* @param _ - The message to sign, as a string or BytesLike object.
|
|
133
|
+
* @returns A promise that resolves to the signature info.
|
|
134
|
+
* @throws Will throw an error if not implemented.
|
|
135
|
+
*/
|
|
136
|
+
async signMessage(message) {
|
|
137
|
+
return {
|
|
138
|
+
signature: await this.signMessageRaw(message),
|
|
139
|
+
identity: await this.getIdentity(),
|
|
140
|
+
signType: this.signType,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Signs a message and returns signature only. This method is not implemented and should be overridden by subclasses.
|
|
145
|
+
*
|
|
146
|
+
* @param _ - The message to sign, as a string or BytesLike object.
|
|
147
|
+
* @returns A promise that resolves to the signature as a string.
|
|
148
|
+
* @throws Will throw an error if not implemented.
|
|
149
|
+
*/
|
|
150
|
+
signMessageRaw(_) {
|
|
151
|
+
throw Error("Signer.signMessageRaw not implemented");
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Verify a signature.
|
|
155
|
+
*
|
|
156
|
+
* @param _ - The original message.
|
|
157
|
+
* @param _ - The signature to verify.
|
|
158
|
+
* @returns A promise that resolves to the verification result.
|
|
159
|
+
* @throws Will throw an error if not implemented.
|
|
160
|
+
*/
|
|
161
|
+
async verifyMessage(message, signature) {
|
|
162
|
+
if (typeof signature === "string") {
|
|
163
|
+
return this.verifyMessageRaw(message, signature);
|
|
164
|
+
}
|
|
165
|
+
if (
|
|
166
|
+
signature.identity !== (await this.getIdentity()) ||
|
|
167
|
+
![SignerSignType.Unknown, this.signType].includes(signature.signType)
|
|
168
|
+
) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
return this.verifyMessageRaw(message, signature.signature);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Verify a string signature. This method is not implemented and should be overridden by subclasses.
|
|
175
|
+
*
|
|
176
|
+
* @param _0 - The original message.
|
|
177
|
+
* @param _1 - The signature to verify.
|
|
178
|
+
* @returns A promise that resolves to the verification result.
|
|
179
|
+
* @throws Will throw an error if not implemented.
|
|
180
|
+
*/
|
|
181
|
+
verifyMessageRaw(_0, _1) {
|
|
182
|
+
throw Error("Signer.verifyMessageRaw not implemented");
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Sends a transaction after signing it.
|
|
186
|
+
*
|
|
187
|
+
* @param tx - The transaction to send, represented as a TransactionLike object.
|
|
188
|
+
* @returns A promise that resolves to the transaction hash as a Hex string.
|
|
189
|
+
*/
|
|
190
|
+
async sendTransaction(tx) {
|
|
191
|
+
return this.client.sendTransaction(await this.signTransaction(tx));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Signs a transaction.
|
|
195
|
+
*
|
|
196
|
+
* @param tx - The transaction to sign, represented as a TransactionLike object.
|
|
197
|
+
* @returns A promise that resolves to the signed Transaction object.
|
|
198
|
+
*/
|
|
199
|
+
async signTransaction(tx) {
|
|
200
|
+
const preparedTx = await this.prepareTransaction(tx);
|
|
201
|
+
return this.signOnlyTransaction(preparedTx);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
205
|
+
*
|
|
206
|
+
* @param _ - The transaction to prepare, represented as a TransactionLike object.
|
|
207
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
208
|
+
* @throws Will throw an error if not implemented.
|
|
209
|
+
*/
|
|
210
|
+
prepareTransaction(_) {
|
|
211
|
+
throw Error("Signer.prepareTransaction not implemented");
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
|
|
215
|
+
*
|
|
216
|
+
* @param _ - The transaction to sign, represented as a TransactionLike object.
|
|
217
|
+
* @returns A promise that resolves to the signed Transaction object.
|
|
218
|
+
* @throws Will throw an error if not implemented.
|
|
219
|
+
*/
|
|
220
|
+
signOnlyTransaction(_) {
|
|
221
|
+
throw Error("Signer.signOnlyTransaction not implemented");
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
exports.Signer = Signer;
|
|
225
|
+
/**
|
|
226
|
+
* A class representing information about a signer, including its type and the signer instance.
|
|
227
|
+
*/
|
|
228
|
+
class SignerInfo {
|
|
229
|
+
constructor(name, signer) {
|
|
230
|
+
this.name = name;
|
|
231
|
+
this.signer = signer;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
exports.SignerInfo = SignerInfo;
|
|
@@ -1,7 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A type safe way to apply a transformer on a value if it's not empty.
|
|
3
|
+
*
|
|
4
|
+
* @param transformer - The transformer.
|
|
5
|
+
* @param value - The value to be transformed.
|
|
6
|
+
* @returns If the value is empty, it remains its type. Otherwise it will be transformed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function apply<T, R>(
|
|
9
|
+
transformer: (val: T) => R,
|
|
10
|
+
value: undefined,
|
|
11
|
+
): undefined;
|
|
12
|
+
/**
|
|
13
|
+
* A type safe way to apply a transformer on a value if it's not empty.
|
|
14
|
+
*
|
|
15
|
+
* @param transformer - The transformer.
|
|
16
|
+
* @param value - The value to be transformed.
|
|
17
|
+
* @returns If the value is empty, it remains its type. Otherwise it will be transformed.
|
|
18
|
+
*/
|
|
19
|
+
export declare function apply<T, R>(
|
|
20
|
+
transformer: (val: T) => R,
|
|
21
|
+
value: null,
|
|
22
|
+
): null;
|
|
23
|
+
/**
|
|
24
|
+
* A type safe way to apply a transformer on a value if it's not empty.
|
|
25
|
+
*
|
|
26
|
+
* @param transformer - The transformer.
|
|
27
|
+
* @param value - The value to be transformed.
|
|
28
|
+
* @returns If the value is empty, it remains its type. Otherwise it will be transformed.
|
|
29
|
+
*/
|
|
3
30
|
export declare function apply<T, R>(transformer: (val: T) => R, value: T): R;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
31
|
+
/**
|
|
32
|
+
* A type safe way to apply a transformer on a value if it's not empty.
|
|
33
|
+
*
|
|
34
|
+
* @param transformer - The transformer.
|
|
35
|
+
* @param value - The value to be transformed.
|
|
36
|
+
* @returns If the value is empty, it remains its type. Otherwise it will be transformed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function apply<T, R>(
|
|
39
|
+
transformer: (val: T) => R,
|
|
40
|
+
value: T | undefined,
|
|
41
|
+
): R | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* A type safe way to apply a transformer on a value if it's not empty.
|
|
44
|
+
*
|
|
45
|
+
* @param transformer - The transformer.
|
|
46
|
+
* @param value - The value to be transformed.
|
|
47
|
+
* @returns If the value is empty, it remains its type. Otherwise it will be transformed.
|
|
48
|
+
*/
|
|
49
|
+
export declare function apply<T, R>(
|
|
50
|
+
transformer: (val: T) => R,
|
|
51
|
+
value: T | null,
|
|
52
|
+
): R | null;
|
|
53
|
+
/**
|
|
54
|
+
* A type safe way to apply a transformer on a value if it's not empty.
|
|
55
|
+
*
|
|
56
|
+
* @param transformer - The transformer.
|
|
57
|
+
* @param value - The value to be transformed.
|
|
58
|
+
* @returns If the value is empty, it remains its type. Otherwise it will be transformed.
|
|
59
|
+
*/
|
|
60
|
+
export declare function apply<T, R>(
|
|
61
|
+
transformer: (val: T) => R,
|
|
62
|
+
value: undefined | null,
|
|
63
|
+
): undefined | null;
|
|
64
|
+
/**
|
|
65
|
+
* Similar to Array.reduce, but the accumulator can returns Promise.
|
|
66
|
+
*
|
|
67
|
+
* @param values - The array to be reduced.
|
|
68
|
+
* @param accumulator - A callback to be called for each value. If it returns null, the previous result will be kept.
|
|
69
|
+
* @returns The accumulated result.
|
|
70
|
+
*/
|
|
71
|
+
export declare function reduceAsync<T, V>(
|
|
72
|
+
values: T[],
|
|
73
|
+
accumulator: (
|
|
74
|
+
a: T,
|
|
75
|
+
b: T,
|
|
76
|
+
) => Promise<T | undefined | null | void> | T | undefined | null | void,
|
|
77
|
+
): Promise<T>;
|
|
78
|
+
/**
|
|
79
|
+
* Similar to Array.reduce, but the accumulator can returns Promise.
|
|
80
|
+
*
|
|
81
|
+
* @param values - The array to be reduced.
|
|
82
|
+
* @param accumulator - A callback to be called for each value. If it returns null, the previous result will be kept.
|
|
83
|
+
* @param init - The initial value.
|
|
84
|
+
* @returns The accumulated result.
|
|
85
|
+
*/
|
|
86
|
+
export declare function reduceAsync<T, V>(
|
|
87
|
+
values: V[],
|
|
88
|
+
accumulator: (
|
|
89
|
+
a: T,
|
|
90
|
+
b: V,
|
|
91
|
+
) => Promise<T | undefined | null | void> | T | undefined | null | void,
|
|
92
|
+
init: T,
|
|
93
|
+
): Promise<T>;
|
|
94
|
+
export declare function isWebview(userAgent: string): boolean;
|
|
95
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,SAAS,GACf,SAAS,CAAC;AACb,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,CAAC;AAC3E,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;AACrE,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,CAAC,GAAG,SAAS,GACnB,CAAC,GAAG,SAAS,CAAC;AACjB,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,CAAC,GAAG,IAAI,GACd,CAAC,GAAG,IAAI,CAAC;AACZ,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,SAAS,GAAG,IAAI,GACtB,SAAS,GAAG,IAAI,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,SAAS,GACf,SAAS,CAAC;AACb;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,CAAC;AAC3E;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;AACrE;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,CAAC,GAAG,SAAS,GACnB,CAAC,GAAG,SAAS,CAAC;AACjB;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,CAAC,GAAG,IAAI,GACd,CAAC,GAAG,IAAI,CAAC;AACZ;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,SAAS,GAAG,IAAI,GACtB,SAAS,GAAG,IAAI,CAAC;AAmBpB;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,CAAC,EACpC,MAAM,EAAE,CAAC,EAAE,EACX,WAAW,EAAE,CACX,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,KACD,OAAO,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,GACtE,OAAO,CAAC,CAAC,CAAC,CAAC;AACd;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,CAAC,EACpC,MAAM,EAAE,CAAC,EAAE,EACX,WAAW,EAAE,CACX,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,KACD,OAAO,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,EACvE,IAAI,EAAE,CAAC,GACN,OAAO,CAAC,CAAC,CAAC,CAAC;AA0Bd,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEpD"}
|
|
@@ -1,10 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.apply = void 0;
|
|
3
|
+
exports.isWebview = exports.reduceAsync = exports.apply = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A type safe way to apply a transformer on a value if it's not empty.
|
|
6
|
+
*
|
|
7
|
+
* @param transformer - The transformer.
|
|
8
|
+
* @param value - The value to be transformed.
|
|
9
|
+
* @returns If the value is empty, it remains its type. Otherwise it will be transformed.
|
|
10
|
+
*/
|
|
4
11
|
function apply(transformer, value) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
if (value == null) {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
return transformer(value);
|
|
9
16
|
}
|
|
10
17
|
exports.apply = apply;
|
|
18
|
+
async function reduceAsync(values, accumulator, init) {
|
|
19
|
+
if (init === undefined) {
|
|
20
|
+
if (values.length === 0) {
|
|
21
|
+
throw new TypeError("Reduce of empty array with no initial value");
|
|
22
|
+
}
|
|
23
|
+
init = values[0];
|
|
24
|
+
values = values.slice(1);
|
|
25
|
+
}
|
|
26
|
+
return values.reduce(
|
|
27
|
+
(current, b) =>
|
|
28
|
+
current.then((v) =>
|
|
29
|
+
Promise.resolve(accumulator(v, b)).then((r) => r ?? v),
|
|
30
|
+
),
|
|
31
|
+
Promise.resolve(init),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
exports.reduceAsync = reduceAsync;
|
|
35
|
+
function isWebview(userAgent) {
|
|
36
|
+
return /webview|wv|ip((?!.*Safari)|(?=.*like Safari))/i.test(userAgent);
|
|
37
|
+
}
|
|
38
|
+
exports.isWebview = isWebview;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/core",
|
|
3
|
-
"version": "0.0.5-alpha.
|
|
3
|
+
"version": "0.0.5-alpha.10",
|
|
4
4
|
"description": "Common Chains Connector Core",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,12 +57,15 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@ckb-lumos/helpers": "^0.22.2",
|
|
60
|
+
"@joyid/ckb": "^0.0.11",
|
|
60
61
|
"@noble/hashes": "^1.4.0",
|
|
62
|
+
"@unisat/wallet-utils": "^1.0.0",
|
|
61
63
|
"abort-controller": "^3.0.0",
|
|
62
64
|
"bech32": "^2.0.0",
|
|
63
65
|
"blake2b": "^2.1.4",
|
|
64
66
|
"buffer": "^6.0.3",
|
|
65
|
-
"cross-fetch": "^4.0.0"
|
|
67
|
+
"cross-fetch": "^4.0.0",
|
|
68
|
+
"ethers": "^6.13.1"
|
|
66
69
|
},
|
|
67
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "91ea3a92b02117905449ce4d2afef88bd3ffcc60"
|
|
68
71
|
}
|
package/src/address/index.ts
CHANGED
|
@@ -66,7 +66,7 @@ export class Address {
|
|
|
66
66
|
if (!client) {
|
|
67
67
|
throw new Error(`Unknown address prefix ${prefix}`);
|
|
68
68
|
}
|
|
69
|
-
const expectedPrefix =
|
|
69
|
+
const expectedPrefix = client.addressPrefix;
|
|
70
70
|
if (expectedPrefix !== prefix) {
|
|
71
71
|
throw new Error(
|
|
72
72
|
`Unknown address prefix ${prefix}, expected ${expectedPrefix}`,
|
|
@@ -86,11 +86,8 @@ export class Address {
|
|
|
86
86
|
* @returns A promise that resolves to an Address instance.
|
|
87
87
|
*/
|
|
88
88
|
|
|
89
|
-
static
|
|
90
|
-
script:
|
|
91
|
-
client: Client,
|
|
92
|
-
): Promise<Address> {
|
|
93
|
-
return Address.from({ script, prefix: await client.getAddressPrefix() });
|
|
89
|
+
static fromScript(script: ScriptLike, client: Client): Address {
|
|
90
|
+
return Address.from({ script, prefix: client.addressPrefix });
|
|
94
91
|
}
|
|
95
92
|
|
|
96
93
|
static async fromKnownScript(
|
|
@@ -103,7 +100,7 @@ export class Address {
|
|
|
103
100
|
...(await client.getKnownScript(script)),
|
|
104
101
|
args,
|
|
105
102
|
},
|
|
106
|
-
prefix:
|
|
103
|
+
prefix: client.addressPrefix,
|
|
107
104
|
});
|
|
108
105
|
}
|
|
109
106
|
|
package/src/ckb/transaction.ts
CHANGED
|
@@ -961,7 +961,7 @@ export class Transaction {
|
|
|
961
961
|
* await tx.setWitnessArgsAt(0, witnessArgs);
|
|
962
962
|
* ```
|
|
963
963
|
*/
|
|
964
|
-
setWitnessArgsAt(index: number, witness: WitnessArgs):
|
|
964
|
+
setWitnessArgsAt(index: number, witness: WitnessArgs): void {
|
|
965
965
|
if (this.witnesses.length < index) {
|
|
966
966
|
this.witnesses.push(
|
|
967
967
|
...Array.from(
|
|
@@ -972,7 +972,6 @@ export class Transaction {
|
|
|
972
972
|
}
|
|
973
973
|
|
|
974
974
|
this.witnesses[index] = hexFrom(witness.toBytes());
|
|
975
|
-
return this;
|
|
976
975
|
}
|
|
977
976
|
|
|
978
977
|
/**
|
|
@@ -992,14 +991,14 @@ export class Transaction {
|
|
|
992
991
|
scriptLike: ScriptLike,
|
|
993
992
|
lockLen: number,
|
|
994
993
|
client: Client,
|
|
995
|
-
): Promise<
|
|
994
|
+
): Promise<void> {
|
|
996
995
|
const position = await this.findInputIndexByLock(scriptLike, client);
|
|
997
996
|
if (position === undefined) {
|
|
998
|
-
return
|
|
997
|
+
return;
|
|
999
998
|
}
|
|
1000
999
|
|
|
1001
1000
|
const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
|
|
1002
1001
|
witness.lock = hexFrom(Array.from(new Array(lockLen), () => 0));
|
|
1003
|
-
|
|
1002
|
+
this.setWitnessArgsAt(position, witness);
|
|
1004
1003
|
}
|
|
1005
1004
|
}
|
package/src/client/client.ts
CHANGED
|
@@ -5,8 +5,10 @@ import {
|
|
|
5
5
|
ScriptLike,
|
|
6
6
|
TransactionLike,
|
|
7
7
|
} from "../ckb";
|
|
8
|
+
import { Zero } from "../fixedPoint";
|
|
8
9
|
import { Hex, HexLike } from "../hex";
|
|
9
|
-
import { NumLike, numFrom } from "../num";
|
|
10
|
+
import { Num, NumLike, numFrom } from "../num";
|
|
11
|
+
import { reduceAsync } from "../utils";
|
|
10
12
|
import {
|
|
11
13
|
ClientFindCellsResponse,
|
|
12
14
|
ClientIndexerSearchKeyLike,
|
|
@@ -24,9 +26,9 @@ export enum KnownScript {
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export abstract class Client {
|
|
27
|
-
abstract
|
|
29
|
+
abstract get url(): string;
|
|
30
|
+
abstract get addressPrefix(): string;
|
|
28
31
|
|
|
29
|
-
abstract getAddressPrefix(): Promise<string>;
|
|
30
32
|
abstract getKnownScript(
|
|
31
33
|
script: KnownScript,
|
|
32
34
|
): Promise<Pick<Script, "codeHash" | "hashType">>;
|
|
@@ -104,4 +106,26 @@ export abstract class Client {
|
|
|
104
106
|
withData,
|
|
105
107
|
});
|
|
106
108
|
}
|
|
109
|
+
|
|
110
|
+
abstract getCellsCapacity(key: ClientIndexerSearchKeyLike): Promise<Num>;
|
|
111
|
+
|
|
112
|
+
async getBalanceSingle(lock: ScriptLike): Promise<Num> {
|
|
113
|
+
return this.getCellsCapacity({
|
|
114
|
+
script: lock,
|
|
115
|
+
scriptType: "lock",
|
|
116
|
+
scriptSearchMode: "exact",
|
|
117
|
+
filter: {
|
|
118
|
+
scriptLenRange: [0, 1],
|
|
119
|
+
outputDataLenRange: [0, 1],
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async getBalance(locks: ScriptLike[]): Promise<Num> {
|
|
125
|
+
return reduceAsync(
|
|
126
|
+
locks,
|
|
127
|
+
async (acc, lock) => acc + (await this.getBalanceSingle(lock)),
|
|
128
|
+
Zero,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
107
131
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fetch from "cross-fetch";
|
|
2
2
|
import { TransactionLike } from "../../ckb";
|
|
3
3
|
import { Hex, HexLike, hexFrom } from "../../hex";
|
|
4
|
-
import { NumLike, numToHex } from "../../num";
|
|
4
|
+
import { Num, NumLike, numFrom, numToHex } from "../../num";
|
|
5
5
|
import { Client } from "../client";
|
|
6
6
|
import {
|
|
7
7
|
ClientFindCellsResponse,
|
|
@@ -49,7 +49,7 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
49
49
|
*/
|
|
50
50
|
|
|
51
51
|
constructor(
|
|
52
|
-
private readonly
|
|
52
|
+
private readonly url_: string,
|
|
53
53
|
private readonly timeout = 30000,
|
|
54
54
|
) {
|
|
55
55
|
super();
|
|
@@ -61,8 +61,8 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
61
61
|
* @returns The URL of the JSON-RPC server.
|
|
62
62
|
*/
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
return this.
|
|
64
|
+
get url() {
|
|
65
|
+
return this.url_;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
@@ -98,7 +98,10 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
98
98
|
/**
|
|
99
99
|
* find cells from node.
|
|
100
100
|
*
|
|
101
|
-
* @param
|
|
101
|
+
* @param key - The search key of cells.
|
|
102
|
+
* @param order - The order of cells.
|
|
103
|
+
* @param limit - The max return size of cells.
|
|
104
|
+
* @param after - Pagination parameter.
|
|
102
105
|
* @returns The found cells.
|
|
103
106
|
*/
|
|
104
107
|
|
|
@@ -117,6 +120,19 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
117
120
|
after?: string,
|
|
118
121
|
) => Promise<ClientFindCellsResponse>;
|
|
119
122
|
|
|
123
|
+
/**
|
|
124
|
+
* get cells capacity from node.
|
|
125
|
+
*
|
|
126
|
+
* @param key - The search key of cells.
|
|
127
|
+
* @returns The sum of cells capacity.
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
getCellsCapacity = this.buildSender(
|
|
131
|
+
"get_cells_capacity",
|
|
132
|
+
[JsonRpcTransformers.indexerSearchKeyFrom],
|
|
133
|
+
({ capacity }) => numFrom(capacity),
|
|
134
|
+
) as (key: ClientIndexerSearchKeyLike) => Promise<Num>;
|
|
135
|
+
|
|
120
136
|
/**
|
|
121
137
|
* Builds a sender function for a JSON-RPC method.
|
|
122
138
|
*
|
package/src/signer/btc/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Transaction, TransactionLike, WitnessArgs } from "../../ckb";
|
|
|
6
6
|
import { KnownScript } from "../../client";
|
|
7
7
|
import { HexLike, hexFrom } from "../../hex";
|
|
8
8
|
import { numToBytes } from "../../num";
|
|
9
|
-
import { Signer } from "../signer";
|
|
9
|
+
import { Signer, SignerSignType, SignerType } from "../signer";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* An abstract class extending the Signer class for Bitcoin-like signing operations.
|
|
@@ -14,6 +14,14 @@ import { Signer } from "../signer";
|
|
|
14
14
|
* as well as signing transactions.
|
|
15
15
|
*/
|
|
16
16
|
export abstract class SignerBtc extends Signer {
|
|
17
|
+
get type(): SignerType {
|
|
18
|
+
return SignerType.BTC;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get signType(): SignerSignType {
|
|
22
|
+
return SignerSignType.BtcEcdsa;
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
/**
|
|
18
26
|
* Gets the Bitcoin account associated with the signer.
|
|
19
27
|
*
|
|
@@ -37,6 +45,15 @@ export abstract class SignerBtc extends Signer {
|
|
|
37
45
|
return this.getBtcAccount();
|
|
38
46
|
}
|
|
39
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Gets the identity, which is the Bitcoin public key in this case.
|
|
50
|
+
*
|
|
51
|
+
* @returns A promise that resolves to a string representing the identity
|
|
52
|
+
*/
|
|
53
|
+
async getIdentity(): Promise<string> {
|
|
54
|
+
return hexFrom(await this.getBtcPublicKey()).slice(2);
|
|
55
|
+
}
|
|
56
|
+
|
|
40
57
|
/**
|
|
41
58
|
* Gets an array of Address objects representing the known script addresses for the signer.
|
|
42
59
|
*
|
|
@@ -62,12 +79,10 @@ export abstract class SignerBtc extends Signer {
|
|
|
62
79
|
* @returns A promise that resolves to the prepared Transaction object.
|
|
63
80
|
*/
|
|
64
81
|
async prepareTransaction(txLike: TransactionLike): Promise<Transaction> {
|
|
82
|
+
const tx = Transaction.from(txLike);
|
|
65
83
|
const { script } = await this.getRecommendedAddressObj();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
85,
|
|
69
|
-
this.client,
|
|
70
|
-
);
|
|
84
|
+
await tx.prepareSighashAllWitness(script, 85, this.client);
|
|
85
|
+
return tx;
|
|
71
86
|
}
|
|
72
87
|
|
|
73
88
|
/**
|
|
@@ -85,7 +100,7 @@ export abstract class SignerBtc extends Signer {
|
|
|
85
100
|
}
|
|
86
101
|
|
|
87
102
|
const signature = bytesFrom(
|
|
88
|
-
await this.
|
|
103
|
+
await this.signMessageRaw(
|
|
89
104
|
`CKB (Bitcoin Layer) transaction: ${info.message}`,
|
|
90
105
|
),
|
|
91
106
|
"base64",
|