@ckb-ccc/core 0.1.0-alpha.6 → 0.1.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 +34 -0
- package/dist/barrel.d.ts +1 -0
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +1 -0
- package/dist/ckb/transactionLumos.d.ts +2 -1
- package/dist/ckb/transactionLumos.d.ts.map +1 -1
- package/dist/client/client.js +1 -1
- package/dist/molecule/codec.d.ts +118 -0
- package/dist/molecule/codec.d.ts.map +1 -0
- package/dist/molecule/codec.js +446 -0
- package/dist/molecule/index.d.ts +3 -0
- package/dist/molecule/index.d.ts.map +1 -0
- package/dist/molecule/index.js +2 -0
- package/dist/molecule/predefined.d.ts +52 -0
- package/dist/molecule/predefined.d.ts.map +1 -0
- package/dist/molecule/predefined.js +95 -0
- package/dist/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist/signer/btc/signerBtc.js +2 -3
- package/dist/signer/btc/verify.d.ts +14 -1
- package/dist/signer/btc/verify.d.ts.map +1 -1
- package/dist/signer/btc/verify.js +22 -1
- package/dist/signer/doge/index.d.ts +5 -0
- package/dist/signer/doge/index.d.ts.map +1 -0
- package/dist/signer/doge/index.js +4 -0
- package/dist/signer/doge/signerDoge.d.ts +52 -0
- package/dist/signer/doge/signerDoge.d.ts.map +1 -0
- package/dist/signer/doge/signerDoge.js +82 -0
- package/dist/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
- package/dist/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
- package/dist/signer/doge/signerDogeAddressReadonly.js +45 -0
- package/dist/signer/doge/signerDogePrivateKey.d.ts +52 -0
- package/dist/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
- package/dist/signer/doge/signerDogePrivateKey.js +68 -0
- package/dist/signer/doge/verify.d.ts +6 -0
- package/dist/signer/doge/verify.d.ts.map +1 -0
- package/dist/signer/doge/verify.js +17 -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/signer/nostr/index.d.ts +1 -0
- package/dist/signer/nostr/index.d.ts.map +1 -1
- package/dist/signer/nostr/index.js +1 -0
- package/dist/signer/signer/index.d.ts +4 -2
- package/dist/signer/signer/index.d.ts.map +1 -1
- package/dist/signer/signer/index.js +5 -0
- package/dist.commonjs/address/address.advanced.js +23 -28
- package/dist.commonjs/address/advanced.js +1 -17
- package/dist.commonjs/address/index.js +11 -15
- package/dist.commonjs/advanced.js +2 -31
- package/dist.commonjs/advancedBarrel.js +5 -21
- package/dist.commonjs/barrel.d.ts +1 -0
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +12 -27
- package/dist.commonjs/bytes/advanced.js +1 -2
- package/dist.commonjs/bytes/index.js +7 -12
- package/dist.commonjs/ckb/advanced.js +3 -32
- package/dist.commonjs/ckb/index.js +3 -19
- package/dist.commonjs/ckb/molecule.advanced/generated.js +64 -131
- package/dist.commonjs/ckb/molecule.advanced/index.js +2 -19
- package/dist.commonjs/ckb/script.advanced.js +3 -6
- package/dist.commonjs/ckb/script.js +23 -53
- package/dist.commonjs/ckb/transaction.advanced.js +3 -6
- package/dist.commonjs/ckb/transaction.js +122 -163
- package/dist.commonjs/ckb/transactionLumos.d.ts +2 -1
- package/dist.commonjs/ckb/transactionLumos.d.ts.map +1 -1
- package/dist.commonjs/ckb/transactionLumos.js +1 -2
- package/dist.commonjs/client/advanced.js +6 -22
- package/dist.commonjs/client/cache/advanced.js +1 -17
- package/dist.commonjs/client/cache/cache.js +3 -7
- package/dist.commonjs/client/cache/index.js +2 -18
- package/dist.commonjs/client/cache/memory.advanced.js +21 -28
- package/dist.commonjs/client/cache/memory.js +19 -23
- package/dist.commonjs/client/client.js +22 -26
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +22 -25
- package/dist.commonjs/client/clientPublicMainnet.js +8 -15
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +22 -25
- package/dist.commonjs/client/clientPublicTestnet.js +8 -15
- package/dist.commonjs/client/clientTypes.advanced.js +3 -6
- package/dist.commonjs/client/clientTypes.js +29 -43
- package/dist.commonjs/client/index.js +6 -22
- package/dist.commonjs/client/jsonRpc/advanced.js +2 -18
- package/dist.commonjs/client/jsonRpc/index.js +37 -41
- package/dist.commonjs/client/jsonRpc/transformers.js +57 -61
- package/dist.commonjs/client/jsonRpc/types.js +1 -2
- package/dist.commonjs/client/transports/advanced.js +8 -25
- package/dist.commonjs/client/transports/http.js +1 -5
- package/dist.commonjs/client/transports/transport.js +1 -2
- package/dist.commonjs/client/transports/webSocket.js +3 -10
- package/dist.commonjs/fixedPoint/index.js +4 -9
- package/dist.commonjs/hasher/advanced.js +1 -4
- package/dist.commonjs/hasher/hasher.js +1 -2
- package/dist.commonjs/hasher/hasherCkb.js +14 -20
- package/dist.commonjs/hasher/hasherKeecak256.js +7 -11
- package/dist.commonjs/hasher/index.js +3 -19
- package/dist.commonjs/hex/index.js +3 -6
- package/dist.commonjs/index.js +2 -31
- package/dist.commonjs/keystore/index.js +21 -25
- package/dist.commonjs/molecule/codec.d.ts +118 -0
- package/dist.commonjs/molecule/codec.d.ts.map +1 -0
- package/dist.commonjs/molecule/codec.js +446 -0
- package/dist.commonjs/molecule/index.d.ts +3 -0
- package/dist.commonjs/molecule/index.d.ts.map +1 -0
- package/dist.commonjs/molecule/index.js +2 -0
- package/dist.commonjs/molecule/predefined.d.ts +52 -0
- package/dist.commonjs/molecule/predefined.d.ts.map +1 -0
- package/dist.commonjs/molecule/predefined.js +95 -0
- package/dist.commonjs/num/index.js +17 -29
- package/dist.commonjs/signer/btc/index.js +3 -19
- package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/signerBtc.js +20 -25
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +4 -8
- package/dist.commonjs/signer/btc/verify.d.ts +14 -1
- package/dist.commonjs/signer/btc/verify.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/verify.js +29 -11
- package/dist.commonjs/signer/ckb/index.js +5 -21
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +16 -20
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +20 -24
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +8 -12
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +12 -16
- package/dist.commonjs/signer/ckb/verifyJoyId.js +5 -8
- package/dist.commonjs/signer/doge/index.d.ts +5 -0
- package/dist.commonjs/signer/doge/index.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/index.js +4 -0
- package/dist.commonjs/signer/doge/signerDoge.d.ts +52 -0
- package/dist.commonjs/signer/doge/signerDoge.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDoge.js +82 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.js +45 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts +52 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.js +68 -0
- package/dist.commonjs/signer/doge/verify.d.ts +6 -0
- package/dist.commonjs/signer/doge/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/verify.js +17 -0
- package/dist.commonjs/signer/dummy/alwaysError.js +2 -6
- package/dist.commonjs/signer/dummy/dummy.js +3 -7
- package/dist.commonjs/signer/dummy/index.js +3 -19
- package/dist.commonjs/signer/dummy/openLink.js +2 -6
- package/dist.commonjs/signer/evm/index.js +3 -19
- package/dist.commonjs/signer/evm/signerEvm.js +31 -35
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +4 -8
- package/dist.commonjs/signer/evm/verify.js +4 -7
- package/dist.commonjs/signer/index.d.ts +1 -0
- package/dist.commonjs/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/index.js +7 -22
- package/dist.commonjs/signer/nostr/index.d.ts +1 -0
- package/dist.commonjs/signer/nostr/index.d.ts.map +1 -1
- package/dist.commonjs/signer/nostr/index.js +2 -17
- package/dist.commonjs/signer/nostr/signerNostr.js +21 -25
- package/dist.commonjs/signer/nostr/verify.js +12 -16
- package/dist.commonjs/signer/signer/index.d.ts +4 -2
- package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/signer/index.js +22 -23
- package/dist.commonjs/utils/index.js +6 -12
- package/package.json +3 -1
- package/src/barrel.ts +1 -0
- package/src/ckb/transactionLumos.ts +2 -1
- package/src/client/client.ts +1 -1
- package/src/molecule/codec.ts +610 -0
- package/src/molecule/index.ts +2 -0
- package/src/molecule/predefined.ts +114 -0
- package/src/signer/btc/signerBtc.ts +2 -3
- package/src/signer/btc/verify.ts +31 -2
- package/src/signer/doge/index.ts +4 -0
- package/src/signer/doge/signerDoge.ts +116 -0
- package/src/signer/doge/signerDogeAddressReadonly.ts +52 -0
- package/src/signer/doge/signerDogePrivateKey.ts +97 -0
- package/src/signer/doge/verify.ts +38 -0
- package/src/signer/index.ts +1 -0
- package/src/signer/nostr/index.ts +1 -0
- package/src/signer/signer/index.ts +9 -0
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.numMin = numMin;
|
|
4
|
-
exports.numMax = numMax;
|
|
5
|
-
exports.numFrom = numFrom;
|
|
6
|
-
exports.numToHex = numToHex;
|
|
7
|
-
exports.numToBytes = numToBytes;
|
|
8
|
-
exports.numLeToBytes = numLeToBytes;
|
|
9
|
-
exports.numBeToBytes = numBeToBytes;
|
|
10
|
-
exports.numFromBytes = numFromBytes;
|
|
11
|
-
exports.numLeFromBytes = numLeFromBytes;
|
|
12
|
-
exports.numBeFromBytes = numBeFromBytes;
|
|
13
|
-
const index_js_1 = require("../bytes/index.js");
|
|
14
|
-
const index_js_2 = require("../hex/index.js");
|
|
1
|
+
import { bytesConcat, bytesFrom } from "../bytes/index.js";
|
|
2
|
+
import { hexFrom } from "../hex/index.js";
|
|
15
3
|
/**
|
|
16
4
|
* Get the min among all numbers.
|
|
17
5
|
* @public
|
|
@@ -24,7 +12,7 @@ const index_js_2 = require("../hex/index.js");
|
|
|
24
12
|
* numMin(1, 2, 3); // Outputs 1n
|
|
25
13
|
* ```
|
|
26
14
|
*/
|
|
27
|
-
function numMin(a, ...numbers) {
|
|
15
|
+
export function numMin(a, ...numbers) {
|
|
28
16
|
let min = numFrom(a);
|
|
29
17
|
numbers.forEach((nLike) => {
|
|
30
18
|
const n = numFrom(nLike);
|
|
@@ -46,7 +34,7 @@ function numMin(a, ...numbers) {
|
|
|
46
34
|
* numMax(1, 2, 3); // Outputs 3n
|
|
47
35
|
* ```
|
|
48
36
|
*/
|
|
49
|
-
function numMax(a, ...numbers) {
|
|
37
|
+
export function numMax(a, ...numbers) {
|
|
50
38
|
let max = numFrom(a);
|
|
51
39
|
numbers.forEach((nLike) => {
|
|
52
40
|
const n = numFrom(nLike);
|
|
@@ -69,14 +57,14 @@ function numMax(a, ...numbers) {
|
|
|
69
57
|
* const numFromHex = numFrom("0x3039"); // Outputs 12345n
|
|
70
58
|
* ```
|
|
71
59
|
*/
|
|
72
|
-
function numFrom(val) {
|
|
60
|
+
export function numFrom(val) {
|
|
73
61
|
if (typeof val === "bigint") {
|
|
74
62
|
return val;
|
|
75
63
|
}
|
|
76
64
|
if (typeof val === "string" || typeof val === "number") {
|
|
77
65
|
return BigInt(val);
|
|
78
66
|
}
|
|
79
|
-
return BigInt(
|
|
67
|
+
return BigInt(hexFrom(val));
|
|
80
68
|
}
|
|
81
69
|
/**
|
|
82
70
|
* Converts a NumLike value to a hexadecimal string.
|
|
@@ -90,7 +78,7 @@ function numFrom(val) {
|
|
|
90
78
|
* const hex = numToHex(12345); // Outputs "0x3039"
|
|
91
79
|
* ```
|
|
92
80
|
*/
|
|
93
|
-
function numToHex(val) {
|
|
81
|
+
export function numToHex(val) {
|
|
94
82
|
return `0x${numFrom(val).toString(16)}`;
|
|
95
83
|
}
|
|
96
84
|
/**
|
|
@@ -106,7 +94,7 @@ function numToHex(val) {
|
|
|
106
94
|
* const bytes = numToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
|
|
107
95
|
* ```
|
|
108
96
|
*/
|
|
109
|
-
function numToBytes(val, bytes) {
|
|
97
|
+
export function numToBytes(val, bytes) {
|
|
110
98
|
return numLeToBytes(val, bytes);
|
|
111
99
|
}
|
|
112
100
|
/**
|
|
@@ -122,7 +110,7 @@ function numToBytes(val, bytes) {
|
|
|
122
110
|
* const bytes = numLeToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
|
|
123
111
|
* ```
|
|
124
112
|
*/
|
|
125
|
-
function numLeToBytes(val, bytes) {
|
|
113
|
+
export function numLeToBytes(val, bytes) {
|
|
126
114
|
return numBeToBytes(val, bytes).reverse();
|
|
127
115
|
}
|
|
128
116
|
/**
|
|
@@ -138,12 +126,12 @@ function numLeToBytes(val, bytes) {
|
|
|
138
126
|
* const bytes = numBeToBytes(12345, 4); // Outputs Uint8Array [0, 0, 48, 57]
|
|
139
127
|
* ```
|
|
140
128
|
*/
|
|
141
|
-
function numBeToBytes(val, bytes) {
|
|
142
|
-
const rawBytes =
|
|
129
|
+
export function numBeToBytes(val, bytes) {
|
|
130
|
+
const rawBytes = bytesFrom(numFrom(val).toString(16));
|
|
143
131
|
if (bytes == null) {
|
|
144
132
|
return rawBytes;
|
|
145
133
|
}
|
|
146
|
-
return
|
|
134
|
+
return bytesConcat(Array.from(Array(bytes - rawBytes.length), () => 0), rawBytes);
|
|
147
135
|
}
|
|
148
136
|
/**
|
|
149
137
|
* Converts a byte array to a Num (bigint) assuming little-endian order.
|
|
@@ -157,7 +145,7 @@ function numBeToBytes(val, bytes) {
|
|
|
157
145
|
* const num = numFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
|
|
158
146
|
* ```
|
|
159
147
|
*/
|
|
160
|
-
function numFromBytes(val) {
|
|
148
|
+
export function numFromBytes(val) {
|
|
161
149
|
return numLeFromBytes(val);
|
|
162
150
|
}
|
|
163
151
|
/**
|
|
@@ -172,8 +160,8 @@ function numFromBytes(val) {
|
|
|
172
160
|
* const num = numLeFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
|
|
173
161
|
* ```
|
|
174
162
|
*/
|
|
175
|
-
function numLeFromBytes(val) {
|
|
176
|
-
return numBeFromBytes([...
|
|
163
|
+
export function numLeFromBytes(val) {
|
|
164
|
+
return numBeFromBytes([...bytesFrom(val)].reverse());
|
|
177
165
|
}
|
|
178
166
|
/**
|
|
179
167
|
* Converts a byte array to a Num (bigint) assuming big-endian order.
|
|
@@ -187,6 +175,6 @@ function numLeFromBytes(val) {
|
|
|
187
175
|
* const num = numBeFromBytes(new Uint8Array([0, 0, 48, 57])); // Outputs 12345n
|
|
188
176
|
* ```
|
|
189
177
|
*/
|
|
190
|
-
function numBeFromBytes(val) {
|
|
191
|
-
return numFrom(
|
|
178
|
+
export function numBeFromBytes(val) {
|
|
179
|
+
return numFrom(bytesFrom(val));
|
|
192
180
|
}
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./signerBtc.js"), exports);
|
|
18
|
-
__exportStar(require("./signerBtcPublicKeyReadonly.js"), exports);
|
|
19
|
-
__exportStar(require("./verify.js"), exports);
|
|
1
|
+
export * from "./signerBtc.js";
|
|
2
|
+
export * from "./signerBtcPublicKeyReadonly.js";
|
|
3
|
+
export * from "./verify.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signerBtc.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signerBtc.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,oBAAoB,CAAC;AAE/E,OAAO,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGxE;;;;;GAKG;AACH,8BAAsB,SAAU,SAAQ,MAAM;IAC5C,IAAI,IAAI,IAAI,UAAU,CAErB;IAED,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAED;;;;OAIG;IACH,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEzC;;;;OAIG;IACH,QAAQ,CAAC,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAE5C;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAIpC;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAa1C;;;;;OAKG;IACG,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAQvE;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CA+BzE"}
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const index_js_4 = require("../../client/index.js");
|
|
10
|
-
const index_js_5 = require("../../hex/index.js");
|
|
11
|
-
const index_js_6 = require("../../num/index.js");
|
|
12
|
-
const index_js_7 = require("../signer/index.js");
|
|
1
|
+
import { Address } from "../../address/index.js";
|
|
2
|
+
import { bytesConcat, bytesFrom } from "../../bytes/index.js";
|
|
3
|
+
import { Transaction, WitnessArgs } from "../../ckb/index.js";
|
|
4
|
+
import { KnownScript } from "../../client/index.js";
|
|
5
|
+
import { hexFrom } from "../../hex/index.js";
|
|
6
|
+
import { numToBytes } from "../../num/index.js";
|
|
7
|
+
import { Signer, SignerSignType, SignerType } from "../signer/index.js";
|
|
8
|
+
import { btcEcdsaPublicKeyHash } from "./verify.js";
|
|
13
9
|
/**
|
|
14
10
|
* An abstract class extending the Signer class for Bitcoin-like signing operations.
|
|
15
11
|
* This class provides methods to get Bitcoin account, public key, and internal address,
|
|
16
12
|
* as well as signing transactions.
|
|
17
13
|
* @public
|
|
18
14
|
*/
|
|
19
|
-
class SignerBtc extends
|
|
15
|
+
export class SignerBtc extends Signer {
|
|
20
16
|
get type() {
|
|
21
|
-
return
|
|
17
|
+
return SignerType.BTC;
|
|
22
18
|
}
|
|
23
19
|
get signType() {
|
|
24
|
-
return
|
|
20
|
+
return SignerSignType.BtcEcdsa;
|
|
25
21
|
}
|
|
26
22
|
/**
|
|
27
23
|
* Gets the internal address, which is the Bitcoin account in this case.
|
|
@@ -37,7 +33,7 @@ class SignerBtc extends index_js_7.Signer {
|
|
|
37
33
|
* @returns A promise that resolves to a string representing the identity
|
|
38
34
|
*/
|
|
39
35
|
async getIdentity() {
|
|
40
|
-
return
|
|
36
|
+
return hexFrom(await this.getBtcPublicKey()).slice(2);
|
|
41
37
|
}
|
|
42
38
|
/**
|
|
43
39
|
* Gets an array of Address objects representing the known script addresses for the signer.
|
|
@@ -46,9 +42,9 @@ class SignerBtc extends index_js_7.Signer {
|
|
|
46
42
|
*/
|
|
47
43
|
async getAddressObjs() {
|
|
48
44
|
const publicKey = await this.getBtcPublicKey();
|
|
49
|
-
const hash = (
|
|
45
|
+
const hash = btcEcdsaPublicKeyHash(publicKey);
|
|
50
46
|
return [
|
|
51
|
-
await
|
|
47
|
+
await Address.fromKnownScript(this.client, KnownScript.OmniLock, hexFrom([0x04, ...hash, 0x00])),
|
|
52
48
|
];
|
|
53
49
|
}
|
|
54
50
|
/**
|
|
@@ -58,9 +54,9 @@ class SignerBtc extends index_js_7.Signer {
|
|
|
58
54
|
* @returns A promise that resolves to the prepared Transaction object.
|
|
59
55
|
*/
|
|
60
56
|
async prepareTransaction(txLike) {
|
|
61
|
-
const tx =
|
|
57
|
+
const tx = Transaction.from(txLike);
|
|
62
58
|
const { script } = await this.getRecommendedAddressObj();
|
|
63
|
-
await tx.addCellDepsOfKnownScripts(this.client,
|
|
59
|
+
await tx.addCellDepsOfKnownScripts(this.client, KnownScript.OmniLock);
|
|
64
60
|
await tx.prepareSighashAllWitness(script, 85, this.client);
|
|
65
61
|
return tx;
|
|
66
62
|
}
|
|
@@ -71,18 +67,17 @@ class SignerBtc extends index_js_7.Signer {
|
|
|
71
67
|
* @returns A promise that resolves to a signed Transaction object.
|
|
72
68
|
*/
|
|
73
69
|
async signOnlyTransaction(txLike) {
|
|
74
|
-
const tx =
|
|
70
|
+
const tx = Transaction.from(txLike);
|
|
75
71
|
const { script } = await this.getRecommendedAddressObj();
|
|
76
72
|
const info = await tx.getSignHashInfo(script, this.client);
|
|
77
73
|
if (!info) {
|
|
78
74
|
return tx;
|
|
79
75
|
}
|
|
80
|
-
const signature =
|
|
76
|
+
const signature = bytesFrom(await this.signMessageRaw(`CKB (Bitcoin Layer) transaction: ${info.message}`), "base64");
|
|
81
77
|
signature[0] = 31 + ((signature[0] - 27) % 4);
|
|
82
|
-
const witness =
|
|
83
|
-
witness.lock =
|
|
78
|
+
const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
79
|
+
witness.lock = hexFrom(bytesConcat(numToBytes(5 * 4 + signature.length, 4), numToBytes(4 * 4, 4), numToBytes(5 * 4 + signature.length, 4), numToBytes(5 * 4 + signature.length, 4), numToBytes(signature.length, 4), signature));
|
|
84
80
|
tx.setWitnessArgsAt(info.position, witness);
|
|
85
81
|
return tx;
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
|
-
exports.SignerBtc = SignerBtc;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.SignerBtcPublicKeyReadonly = void 0;
|
|
4
|
-
const index_js_1 = require("../../hex/index.js");
|
|
5
|
-
const signerBtc_js_1 = require("./signerBtc.js");
|
|
1
|
+
import { hexFrom } from "../../hex/index.js";
|
|
2
|
+
import { SignerBtc } from "./signerBtc.js";
|
|
6
3
|
/**
|
|
7
4
|
* A class extending SignerBtc that provides read-only access to a Bitcoin public key and account.
|
|
8
5
|
* This class does not support signing operations.
|
|
9
6
|
* @public
|
|
10
7
|
*/
|
|
11
|
-
class SignerBtcPublicKeyReadonly extends
|
|
8
|
+
export class SignerBtcPublicKeyReadonly extends SignerBtc {
|
|
12
9
|
/**
|
|
13
10
|
* Creates an instance of SignerBtcPublicKeyReadonly.
|
|
14
11
|
*
|
|
@@ -19,7 +16,7 @@ class SignerBtcPublicKeyReadonly extends signerBtc_js_1.SignerBtc {
|
|
|
19
16
|
constructor(client, account, publicKey) {
|
|
20
17
|
super(client);
|
|
21
18
|
this.account = account;
|
|
22
|
-
this.publicKey =
|
|
19
|
+
this.publicKey = hexFrom(publicKey);
|
|
23
20
|
}
|
|
24
21
|
/**
|
|
25
22
|
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
@@ -62,4 +59,3 @@ class SignerBtcPublicKeyReadonly extends signerBtc_js_1.SignerBtc {
|
|
|
62
59
|
return this.publicKey;
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
|
-
exports.SignerBtcPublicKeyReadonly = SignerBtcPublicKeyReadonly;
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
import { BytesLike } from "../../bytes/index.js";
|
|
1
|
+
import { Bytes, BytesLike } from "../../bytes/index.js";
|
|
2
|
+
import { Hex } from "../../hex/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare function btcEcdsaPublicKeyHash(publicKey: BytesLike): Bytes;
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare function btcP2pkhAddressFromPublicKey(publicKey: BytesLike, network: number): string;
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare function btcPublicKeyFromP2pkhAddress(address: string): Hex;
|
|
2
15
|
/**
|
|
3
16
|
* @public
|
|
4
17
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/verify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/verify.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,SAAS,EAA0B,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,GAAG,EAAW,MAAM,oBAAoB,CAAC;AAElD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,SAAS,GAAG,KAAK,CAEjE;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CAIR;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAEjE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAOT"}
|
|
@@ -1,15 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
2
|
+
import { ripemd160 } from "@noble/hashes/ripemd160";
|
|
3
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
4
|
+
import { magicHash } from "bitcoinjs-message";
|
|
5
|
+
import bs58check from "bs58check";
|
|
6
|
+
import { bytesConcat, bytesFrom } from "../../bytes/index.js";
|
|
7
|
+
import { hexFrom } from "../../hex/index.js";
|
|
8
8
|
/**
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
export function btcEcdsaPublicKeyHash(publicKey) {
|
|
12
|
+
return ripemd160(sha256(bytesFrom(publicKey)));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export function btcP2pkhAddressFromPublicKey(publicKey, network) {
|
|
18
|
+
return bs58check.encode(bytesConcat([network], btcEcdsaPublicKeyHash(publicKey)));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export function btcPublicKeyFromP2pkhAddress(address) {
|
|
24
|
+
return hexFrom(bs58check.decode(address).slice(1));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export function verifyMessageBtcEcdsa(message, signature, publicKey) {
|
|
30
|
+
const challenge = typeof message === "string" ? message : hexFrom(message).slice(2);
|
|
31
|
+
const [_, ...rawSign] = bytesFrom(signature, "base64");
|
|
32
|
+
return secp256k1.verify(bytesFrom(rawSign), magicHash(challenge), publicKey);
|
|
15
33
|
}
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./signerCkbPrivateKey.js"), exports);
|
|
18
|
-
__exportStar(require("./signerCkbPublicKey.js"), exports);
|
|
19
|
-
__exportStar(require("./signerCkbScriptReadonly.js"), exports);
|
|
20
|
-
__exportStar(require("./verifyCkbSecp256k1.js"), exports);
|
|
21
|
-
__exportStar(require("./verifyJoyId.js"), exports);
|
|
1
|
+
export * from "./signerCkbPrivateKey.js";
|
|
2
|
+
export * from "./signerCkbPublicKey.js";
|
|
3
|
+
export * from "./signerCkbScriptReadonly.js";
|
|
4
|
+
export * from "./verifyCkbSecp256k1.js";
|
|
5
|
+
export * from "./verifyJoyId.js";
|
|
@@ -1,46 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const index_js_4 = require("../../num/index.js");
|
|
9
|
-
const signerCkbPublicKey_js_1 = require("./signerCkbPublicKey.js");
|
|
10
|
-
const verifyCkbSecp256k1_js_1 = require("./verifyCkbSecp256k1.js");
|
|
1
|
+
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
2
|
+
import { bytesConcat, bytesFrom } from "../../bytes/index.js";
|
|
3
|
+
import { Transaction, WitnessArgs } from "../../ckb/index.js";
|
|
4
|
+
import { hexFrom } from "../../hex/index.js";
|
|
5
|
+
import { numBeToBytes } from "../../num/index.js";
|
|
6
|
+
import { SignerCkbPublicKey } from "./signerCkbPublicKey.js";
|
|
7
|
+
import { messageHashCkbSecp256k1 } from "./verifyCkbSecp256k1.js";
|
|
11
8
|
/**
|
|
12
9
|
* @public
|
|
13
10
|
*/
|
|
14
|
-
class SignerCkbPrivateKey extends
|
|
11
|
+
export class SignerCkbPrivateKey extends SignerCkbPublicKey {
|
|
15
12
|
constructor(client, privateKey) {
|
|
16
|
-
const pk =
|
|
17
|
-
if (
|
|
13
|
+
const pk = hexFrom(privateKey);
|
|
14
|
+
if (bytesFrom(pk).length !== 32) {
|
|
18
15
|
throw new Error("Private key must be 32 bytes!");
|
|
19
16
|
}
|
|
20
|
-
super(client,
|
|
17
|
+
super(client, secp256k1.getPublicKey(bytesFrom(pk), true));
|
|
21
18
|
this.privateKey = pk;
|
|
22
19
|
}
|
|
23
20
|
async _signMessage(message) {
|
|
24
|
-
const signature =
|
|
21
|
+
const signature = secp256k1.sign(bytesFrom(message), bytesFrom(this.privateKey));
|
|
25
22
|
const { r, s, recovery } = signature;
|
|
26
|
-
return
|
|
23
|
+
return hexFrom(bytesConcat(numBeToBytes(r, 32), numBeToBytes(s, 32), numBeToBytes(recovery, 1)));
|
|
27
24
|
}
|
|
28
25
|
async signMessageRaw(message) {
|
|
29
|
-
return this._signMessage(
|
|
26
|
+
return this._signMessage(messageHashCkbSecp256k1(message));
|
|
30
27
|
}
|
|
31
28
|
async signOnlyTransaction(txLike) {
|
|
32
|
-
const tx =
|
|
29
|
+
const tx = Transaction.from(txLike);
|
|
33
30
|
for (const { script } of await this.getRelatedScripts(tx)) {
|
|
34
31
|
const info = await tx.getSignHashInfo(script, this.client);
|
|
35
32
|
if (!info) {
|
|
36
33
|
return tx;
|
|
37
34
|
}
|
|
38
35
|
const signature = await this._signMessage(info.message);
|
|
39
|
-
const witness = tx.getWitnessArgsAt(info.position) ??
|
|
36
|
+
const witness = tx.getWitnessArgsAt(info.position) ?? WitnessArgs.from({});
|
|
40
37
|
witness.lock = signature;
|
|
41
38
|
tx.setWitnessArgsAt(info.position, witness);
|
|
42
39
|
}
|
|
43
40
|
return tx;
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
|
-
exports.SignerCkbPrivateKey = SignerCkbPrivateKey;
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const index_js_5 = require("../../hasher/index.js");
|
|
9
|
-
const index_js_6 = require("../../hex/index.js");
|
|
10
|
-
const index_js_7 = require("../signer/index.js");
|
|
1
|
+
import { Address } from "../../address/index.js";
|
|
2
|
+
import { bytesFrom } from "../../bytes/index.js";
|
|
3
|
+
import { Script, Transaction } from "../../ckb/index.js";
|
|
4
|
+
import { KnownScript } from "../../client/index.js";
|
|
5
|
+
import { hashCkb } from "../../hasher/index.js";
|
|
6
|
+
import { hexFrom } from "../../hex/index.js";
|
|
7
|
+
import { Signer, SignerSignType, SignerType } from "../signer/index.js";
|
|
11
8
|
/**
|
|
12
9
|
* @public
|
|
13
10
|
*/
|
|
14
|
-
class SignerCkbPublicKey extends
|
|
11
|
+
export class SignerCkbPublicKey extends Signer {
|
|
15
12
|
get type() {
|
|
16
|
-
return
|
|
13
|
+
return SignerType.CKB;
|
|
17
14
|
}
|
|
18
15
|
get signType() {
|
|
19
|
-
return
|
|
16
|
+
return SignerSignType.CkbSecp256k1;
|
|
20
17
|
}
|
|
21
18
|
constructor(client, publicKey) {
|
|
22
19
|
super(client);
|
|
23
|
-
this.publicKey =
|
|
24
|
-
if (
|
|
20
|
+
this.publicKey = hexFrom(publicKey);
|
|
21
|
+
if (bytesFrom(this.publicKey).length !== 33) {
|
|
25
22
|
throw new Error("Public key must be 33 bytes!");
|
|
26
23
|
}
|
|
27
24
|
}
|
|
@@ -36,7 +33,7 @@ class SignerCkbPublicKey extends index_js_7.Signer {
|
|
|
36
33
|
return this.publicKey;
|
|
37
34
|
}
|
|
38
35
|
async getAddressObjSecp256k1() {
|
|
39
|
-
return
|
|
36
|
+
return Address.fromKnownScript(this.client, KnownScript.Secp256k1Blake160, bytesFrom(hashCkb(this.publicKey)).slice(0, 20));
|
|
40
37
|
}
|
|
41
38
|
async getRecommendedAddressObj(_preference) {
|
|
42
39
|
return this.getAddressObjSecp256k1();
|
|
@@ -46,7 +43,7 @@ class SignerCkbPublicKey extends index_js_7.Signer {
|
|
|
46
43
|
const addresses = [];
|
|
47
44
|
let count = 0;
|
|
48
45
|
for await (const cell of this.client.findCells({
|
|
49
|
-
script: await
|
|
46
|
+
script: await Script.fromKnownScript(this.client, KnownScript.AnyoneCanPay, secp256k1.script.args),
|
|
50
47
|
scriptType: "lock",
|
|
51
48
|
scriptSearchMode: "prefix",
|
|
52
49
|
withData: false,
|
|
@@ -58,7 +55,7 @@ class SignerCkbPublicKey extends index_js_7.Signer {
|
|
|
58
55
|
if (addresses.some(({ script }) => script.eq(cell.cellOutput.lock))) {
|
|
59
56
|
continue;
|
|
60
57
|
}
|
|
61
|
-
addresses.push(
|
|
58
|
+
addresses.push(Address.from({
|
|
62
59
|
prefix: this.client.addressPrefix,
|
|
63
60
|
script: cell.cellOutput.lock,
|
|
64
61
|
}));
|
|
@@ -66,9 +63,9 @@ class SignerCkbPublicKey extends index_js_7.Signer {
|
|
|
66
63
|
return [secp256k1, ...addresses];
|
|
67
64
|
}
|
|
68
65
|
async getRelatedScripts(txLike) {
|
|
69
|
-
const tx =
|
|
66
|
+
const tx = Transaction.from(txLike);
|
|
70
67
|
const secp256k1 = await this.getAddressObjSecp256k1();
|
|
71
|
-
const acp = await
|
|
68
|
+
const acp = await Script.fromKnownScript(this.client, KnownScript.AnyoneCanPay, secp256k1.script.args);
|
|
72
69
|
const scripts = [];
|
|
73
70
|
for (const input of tx.inputs) {
|
|
74
71
|
await input.completeExtraInfos(this.client);
|
|
@@ -82,7 +79,7 @@ class SignerCkbPublicKey extends index_js_7.Signer {
|
|
|
82
79
|
if (lock.eq(secp256k1.script)) {
|
|
83
80
|
scripts.push({
|
|
84
81
|
script: lock,
|
|
85
|
-
cellDeps: (await this.client.getKnownScript(
|
|
82
|
+
cellDeps: (await this.client.getKnownScript(KnownScript.Secp256k1Blake160)).cellDeps,
|
|
86
83
|
});
|
|
87
84
|
}
|
|
88
85
|
else if (lock.codeHash === acp.codeHash &&
|
|
@@ -90,7 +87,7 @@ class SignerCkbPublicKey extends index_js_7.Signer {
|
|
|
90
87
|
lock.args.startsWith(acp.args)) {
|
|
91
88
|
scripts.push({
|
|
92
89
|
script: lock,
|
|
93
|
-
cellDeps: (await this.client.getKnownScript(
|
|
90
|
+
cellDeps: (await this.client.getKnownScript(KnownScript.AnyoneCanPay))
|
|
94
91
|
.cellDeps,
|
|
95
92
|
});
|
|
96
93
|
}
|
|
@@ -98,7 +95,7 @@ class SignerCkbPublicKey extends index_js_7.Signer {
|
|
|
98
95
|
return scripts;
|
|
99
96
|
}
|
|
100
97
|
async prepareTransaction(txLike) {
|
|
101
|
-
const tx =
|
|
98
|
+
const tx = Transaction.from(txLike);
|
|
102
99
|
await Promise.all((await this.getRelatedScripts(tx)).map(async ({ script, cellDeps }) => {
|
|
103
100
|
await tx.prepareSighashAllWitness(script, 65, this.client);
|
|
104
101
|
await tx.addCellDepInfos(this.client, cellDeps);
|
|
@@ -106,4 +103,3 @@ class SignerCkbPublicKey extends index_js_7.Signer {
|
|
|
106
103
|
return tx;
|
|
107
104
|
}
|
|
108
105
|
}
|
|
109
|
-
exports.SignerCkbPublicKey = SignerCkbPublicKey;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const index_js_1 = require("../../address/index.js");
|
|
5
|
-
const index_js_2 = require("../../ckb/index.js");
|
|
6
|
-
const index_js_3 = require("../signer/index.js");
|
|
1
|
+
import { Address } from "../../address/index.js";
|
|
2
|
+
import { Script } from "../../ckb/index.js";
|
|
3
|
+
import { Signer, SignerSignType, SignerType } from "../signer/index.js";
|
|
7
4
|
/**
|
|
8
5
|
* A class extending Signer that provides read-only access to a CKB script.
|
|
9
6
|
* This class does not support signing operations.
|
|
10
7
|
* @public
|
|
11
8
|
*/
|
|
12
|
-
class SignerCkbScriptReadonly extends
|
|
9
|
+
export class SignerCkbScriptReadonly extends Signer {
|
|
13
10
|
get type() {
|
|
14
|
-
return
|
|
11
|
+
return SignerType.CKB;
|
|
15
12
|
}
|
|
16
13
|
get signType() {
|
|
17
|
-
return
|
|
14
|
+
return SignerSignType.Unknown;
|
|
18
15
|
}
|
|
19
16
|
/**
|
|
20
17
|
* Creates an instance of SignerCkbScriptReadonly.
|
|
@@ -24,7 +21,7 @@ class SignerCkbScriptReadonly extends index_js_3.Signer {
|
|
|
24
21
|
*/
|
|
25
22
|
constructor(client, script) {
|
|
26
23
|
super(client);
|
|
27
|
-
this.script =
|
|
24
|
+
this.script = Script.from(script);
|
|
28
25
|
}
|
|
29
26
|
/**
|
|
30
27
|
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
@@ -64,7 +61,6 @@ class SignerCkbScriptReadonly extends index_js_3.Signer {
|
|
|
64
61
|
* ```
|
|
65
62
|
*/
|
|
66
63
|
async getAddressObjs() {
|
|
67
|
-
return [
|
|
64
|
+
return [Address.fromScript(this.script, this.client)];
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
|
-
exports.SignerCkbScriptReadonly = SignerCkbScriptReadonly;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const index_js_1 = require("../../bytes/index.js");
|
|
7
|
-
const index_js_2 = require("../../hasher/index.js");
|
|
8
|
-
const index_js_3 = require("../../hex/index.js");
|
|
9
|
-
const index_js_4 = require("../../num/index.js");
|
|
1
|
+
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
2
|
+
import { bytesFrom } from "../../bytes/index.js";
|
|
3
|
+
import { hashCkb } from "../../hasher/index.js";
|
|
4
|
+
import { hexFrom } from "../../hex/index.js";
|
|
5
|
+
import { numFrom } from "../../num/index.js";
|
|
10
6
|
/**
|
|
11
7
|
* @public
|
|
12
8
|
*/
|
|
13
|
-
function messageHashCkbSecp256k1(message) {
|
|
14
|
-
const msg = typeof message === "string" ? message :
|
|
15
|
-
const buffer =
|
|
16
|
-
return
|
|
9
|
+
export function messageHashCkbSecp256k1(message) {
|
|
10
|
+
const msg = typeof message === "string" ? message : hexFrom(message);
|
|
11
|
+
const buffer = bytesFrom(`Nervos Message:${msg}`, "utf8");
|
|
12
|
+
return hashCkb(buffer);
|
|
17
13
|
}
|
|
18
14
|
/**
|
|
19
15
|
* @public
|
|
20
16
|
*/
|
|
21
|
-
function verifyMessageCkbSecp256k1(message, signature, publicKey) {
|
|
22
|
-
const signatureBytes =
|
|
23
|
-
return
|
|
17
|
+
export function verifyMessageCkbSecp256k1(message, signature, publicKey) {
|
|
18
|
+
const signatureBytes = bytesFrom(signature);
|
|
19
|
+
return secp256k1.verify(new secp256k1.Signature(numFrom(signatureBytes.slice(0, 32)), numFrom(signatureBytes.slice(32, 64))).addRecoveryBit(Number(numFrom(signatureBytes.slice(64, 65)))), bytesFrom(messageHashCkbSecp256k1(message)), bytesFrom(publicKey));
|
|
24
20
|
}
|