@ckb-ccc/core 0.1.0 → 0.1.2
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 +12 -0
- package/dist.commonjs/address/address.advanced.js +28 -23
- package/dist.commonjs/address/advanced.js +17 -1
- package/dist.commonjs/address/index.js +15 -11
- package/dist.commonjs/advanced.js +31 -2
- package/dist.commonjs/advancedBarrel.js +21 -5
- package/dist.commonjs/barrel.js +41 -12
- package/dist.commonjs/bytes/advanced.js +2 -1
- package/dist.commonjs/bytes/index.js +12 -7
- package/dist.commonjs/ckb/advanced.js +32 -3
- package/dist.commonjs/ckb/index.js +19 -3
- package/dist.commonjs/ckb/molecule.advanced/generated.js +131 -64
- package/dist.commonjs/ckb/molecule.advanced/index.js +19 -2
- package/dist.commonjs/ckb/script.advanced.js +6 -3
- package/dist.commonjs/ckb/script.js +53 -23
- package/dist.commonjs/ckb/transaction.advanced.js +6 -3
- package/dist.commonjs/ckb/transaction.js +163 -122
- package/dist.commonjs/ckb/transactionLumos.js +2 -1
- package/dist.commonjs/client/advanced.js +22 -6
- package/dist.commonjs/client/cache/advanced.js +17 -1
- package/dist.commonjs/client/cache/cache.js +7 -3
- package/dist.commonjs/client/cache/index.js +18 -2
- package/dist.commonjs/client/cache/memory.advanced.js +28 -21
- package/dist.commonjs/client/cache/memory.js +23 -19
- package/dist.commonjs/client/client.js +25 -21
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +25 -22
- package/dist.commonjs/client/clientPublicMainnet.js +15 -8
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +25 -22
- package/dist.commonjs/client/clientPublicTestnet.js +15 -8
- package/dist.commonjs/client/clientTypes.advanced.js +6 -3
- package/dist.commonjs/client/clientTypes.js +43 -29
- package/dist.commonjs/client/index.js +22 -6
- package/dist.commonjs/client/jsonRpc/advanced.js +18 -2
- package/dist.commonjs/client/jsonRpc/index.js +41 -37
- package/dist.commonjs/client/jsonRpc/transformers.js +61 -57
- package/dist.commonjs/client/jsonRpc/types.js +2 -1
- package/dist.commonjs/client/transports/advanced.js +25 -8
- package/dist.commonjs/client/transports/http.js +5 -1
- package/dist.commonjs/client/transports/transport.js +2 -1
- package/dist.commonjs/client/transports/webSocket.js +10 -3
- package/dist.commonjs/fixedPoint/index.js +9 -4
- package/dist.commonjs/hasher/advanced.js +4 -1
- package/dist.commonjs/hasher/hasher.js +2 -1
- package/dist.commonjs/hasher/hasherCkb.js +20 -14
- package/dist.commonjs/hasher/hasherKeecak256.js +11 -7
- package/dist.commonjs/hasher/index.js +19 -3
- package/dist.commonjs/hex/index.js +6 -3
- package/dist.commonjs/index.js +31 -2
- package/dist.commonjs/keystore/index.js +25 -21
- package/dist.commonjs/molecule/codec.js +63 -48
- package/dist.commonjs/molecule/index.js +18 -2
- package/dist.commonjs/molecule/predefined.js +103 -77
- package/dist.commonjs/num/index.js +29 -17
- package/dist.commonjs/signer/btc/index.js +19 -3
- package/dist.commonjs/signer/btc/signerBtc.js +24 -20
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +8 -4
- package/dist.commonjs/signer/btc/verify.js +26 -17
- package/dist.commonjs/signer/ckb/index.js +21 -5
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +20 -16
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +24 -20
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +12 -8
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +16 -12
- package/dist.commonjs/signer/ckb/verifyJoyId.js +8 -5
- package/dist.commonjs/signer/doge/index.js +20 -4
- package/dist.commonjs/signer/doge/signerDoge.js +26 -19
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.js +6 -2
- package/dist.commonjs/signer/doge/signerDogePrivateKey.js +17 -13
- package/dist.commonjs/signer/doge/verify.js +15 -12
- package/dist.commonjs/signer/dummy/alwaysError.js +6 -2
- package/dist.commonjs/signer/dummy/dummy.js +7 -3
- package/dist.commonjs/signer/dummy/index.js +19 -3
- package/dist.commonjs/signer/dummy/openLink.js +6 -2
- package/dist.commonjs/signer/evm/index.js +19 -3
- package/dist.commonjs/signer/evm/signerEvm.js +35 -31
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +8 -4
- package/dist.commonjs/signer/evm/verify.js +7 -4
- package/dist.commonjs/signer/index.js +23 -7
- package/dist.commonjs/signer/nostr/index.js +18 -2
- package/dist.commonjs/signer/nostr/signerNostr.js +25 -21
- package/dist.commonjs/signer/nostr/verify.js +16 -12
- package/dist.commonjs/signer/signer/index.js +25 -19
- package/dist.commonjs/utils/index.js +12 -6
- package/package.json +6 -2
|
@@ -1,95 +1,121 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export const Uint128 = Uint128LE;
|
|
18
|
-
export const Uint256LE = uint(32, true);
|
|
19
|
-
export const Uint256BE = uint(32);
|
|
20
|
-
export const Uint256 = Uint256LE;
|
|
21
|
-
export const Uint512LE = uint(64, true);
|
|
22
|
-
export const Uint512BE = uint(64);
|
|
23
|
-
export const Uint512 = Uint512LE;
|
|
24
|
-
export const Uint8Opt = option(Uint8);
|
|
25
|
-
export const Uint16Opt = option(Uint16);
|
|
26
|
-
export const Uint32Opt = option(Uint32);
|
|
27
|
-
export const Uint64Opt = option(Uint64);
|
|
28
|
-
export const Uint128Opt = option(Uint128);
|
|
29
|
-
export const Uint256Opt = option(Uint256);
|
|
30
|
-
export const Uint512Opt = option(Uint512);
|
|
31
|
-
export const Bytes = byteVec({
|
|
32
|
-
encode: (value) => bytesFrom(value),
|
|
33
|
-
decode: (buffer) => hexFrom(buffer),
|
|
1
|
+
"use strict";
|
|
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;
|
|
34
17
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Transaction = exports.CellDepVec = exports.CellDep = exports.DepType = exports.CellOutputVec = exports.CellOutput = exports.CellInputVec = exports.CellInput = exports.OutPoint = exports.ScriptOpt = exports.Script = exports.HashType = exports.Hash = exports.StringOpt = exports.StringVec = exports.String = exports.Byte32Vec = exports.Byte32Opt = exports.Byte32 = exports.BytesVec = exports.BytesOpt = exports.Bytes = exports.Uint512Opt = exports.Uint256Opt = exports.Uint128Opt = exports.Uint64Opt = exports.Uint32Opt = exports.Uint16Opt = exports.Uint8Opt = exports.Uint512 = exports.Uint512BE = exports.Uint512LE = exports.Uint256 = exports.Uint256BE = exports.Uint256LE = exports.Uint128 = exports.Uint128BE = exports.Uint128LE = exports.Uint64 = exports.Uint64BE = exports.Uint64LE = exports.Uint32 = exports.Uint32BE = exports.Uint32LE = exports.Uint16 = exports.Uint16BE = exports.Uint16LE = exports.Uint8 = void 0;
|
|
27
|
+
const index_js_1 = require("../bytes/index.js");
|
|
28
|
+
const ckb = __importStar(require("../ckb/index.js"));
|
|
29
|
+
const index_js_2 = require("../hex/index.js");
|
|
30
|
+
const codec_js_1 = require("./codec.js");
|
|
31
|
+
exports.Uint8 = (0, codec_js_1.uintNumber)(1, true);
|
|
32
|
+
exports.Uint16LE = (0, codec_js_1.uintNumber)(2, true);
|
|
33
|
+
exports.Uint16BE = (0, codec_js_1.uintNumber)(2);
|
|
34
|
+
exports.Uint16 = exports.Uint16LE;
|
|
35
|
+
exports.Uint32LE = (0, codec_js_1.uintNumber)(4, true);
|
|
36
|
+
exports.Uint32BE = (0, codec_js_1.uintNumber)(4);
|
|
37
|
+
exports.Uint32 = exports.Uint32LE;
|
|
38
|
+
exports.Uint64LE = (0, codec_js_1.uint)(8, true);
|
|
39
|
+
exports.Uint64BE = (0, codec_js_1.uint)(8);
|
|
40
|
+
exports.Uint64 = exports.Uint64LE;
|
|
41
|
+
exports.Uint128LE = (0, codec_js_1.uint)(16, true);
|
|
42
|
+
exports.Uint128BE = (0, codec_js_1.uint)(16);
|
|
43
|
+
exports.Uint128 = exports.Uint128LE;
|
|
44
|
+
exports.Uint256LE = (0, codec_js_1.uint)(32, true);
|
|
45
|
+
exports.Uint256BE = (0, codec_js_1.uint)(32);
|
|
46
|
+
exports.Uint256 = exports.Uint256LE;
|
|
47
|
+
exports.Uint512LE = (0, codec_js_1.uint)(64, true);
|
|
48
|
+
exports.Uint512BE = (0, codec_js_1.uint)(64);
|
|
49
|
+
exports.Uint512 = exports.Uint512LE;
|
|
50
|
+
exports.Uint8Opt = (0, codec_js_1.option)(exports.Uint8);
|
|
51
|
+
exports.Uint16Opt = (0, codec_js_1.option)(exports.Uint16);
|
|
52
|
+
exports.Uint32Opt = (0, codec_js_1.option)(exports.Uint32);
|
|
53
|
+
exports.Uint64Opt = (0, codec_js_1.option)(exports.Uint64);
|
|
54
|
+
exports.Uint128Opt = (0, codec_js_1.option)(exports.Uint128);
|
|
55
|
+
exports.Uint256Opt = (0, codec_js_1.option)(exports.Uint256);
|
|
56
|
+
exports.Uint512Opt = (0, codec_js_1.option)(exports.Uint512);
|
|
57
|
+
exports.Bytes = (0, codec_js_1.byteVec)({
|
|
58
|
+
encode: (value) => (0, index_js_1.bytesFrom)(value),
|
|
59
|
+
decode: (buffer) => (0, index_js_2.hexFrom)(buffer),
|
|
60
|
+
});
|
|
61
|
+
exports.BytesOpt = (0, codec_js_1.option)(exports.Bytes);
|
|
62
|
+
exports.BytesVec = (0, codec_js_1.vector)(exports.Bytes);
|
|
63
|
+
exports.Byte32 = codec_js_1.Codec.from({
|
|
38
64
|
byteLength: 32,
|
|
39
|
-
encode: (value) => bytesFrom(value),
|
|
40
|
-
decode: (buffer) => hexFrom(buffer),
|
|
65
|
+
encode: (value) => (0, index_js_1.bytesFrom)(value),
|
|
66
|
+
decode: (buffer) => (0, index_js_2.hexFrom)(buffer),
|
|
41
67
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
encode: (value) => bytesFrom(value, "utf8"),
|
|
46
|
-
decode: (buffer) => bytesTo(buffer, "utf8"),
|
|
68
|
+
exports.Byte32Opt = (0, codec_js_1.option)(exports.Byte32);
|
|
69
|
+
exports.Byte32Vec = (0, codec_js_1.vector)(exports.Byte32);
|
|
70
|
+
exports.String = (0, codec_js_1.byteVec)({
|
|
71
|
+
encode: (value) => (0, index_js_1.bytesFrom)(value, "utf8"),
|
|
72
|
+
decode: (buffer) => (0, index_js_1.bytesTo)(buffer, "utf8"),
|
|
47
73
|
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
74
|
+
exports.StringVec = (0, codec_js_1.vector)(exports.String);
|
|
75
|
+
exports.StringOpt = (0, codec_js_1.option)(exports.String);
|
|
76
|
+
exports.Hash = exports.Byte32;
|
|
77
|
+
exports.HashType = codec_js_1.Codec.from({
|
|
52
78
|
byteLength: 1,
|
|
53
79
|
encode: ckb.hashTypeToBytes,
|
|
54
80
|
decode: ckb.hashTypeFromBytes,
|
|
55
81
|
});
|
|
56
|
-
|
|
57
|
-
codeHash: Hash,
|
|
58
|
-
hashType: HashType,
|
|
59
|
-
args: Bytes,
|
|
82
|
+
exports.Script = (0, codec_js_1.table)({
|
|
83
|
+
codeHash: exports.Hash,
|
|
84
|
+
hashType: exports.HashType,
|
|
85
|
+
args: exports.Bytes,
|
|
60
86
|
}).map({ outMap: ckb.Script.from });
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
txHash: Hash,
|
|
64
|
-
index: Uint32,
|
|
87
|
+
exports.ScriptOpt = (0, codec_js_1.option)(exports.Script);
|
|
88
|
+
exports.OutPoint = (0, codec_js_1.struct)({
|
|
89
|
+
txHash: exports.Hash,
|
|
90
|
+
index: exports.Uint32,
|
|
65
91
|
}).map({ outMap: ckb.OutPoint.from });
|
|
66
|
-
|
|
67
|
-
previousOutput: OutPoint,
|
|
68
|
-
since: Uint64,
|
|
92
|
+
exports.CellInput = (0, codec_js_1.struct)({
|
|
93
|
+
previousOutput: exports.OutPoint,
|
|
94
|
+
since: exports.Uint64,
|
|
69
95
|
}).map({ outMap: ckb.CellInput.from });
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
capacity: Uint64,
|
|
73
|
-
lock: Script,
|
|
74
|
-
type: ScriptOpt,
|
|
96
|
+
exports.CellInputVec = (0, codec_js_1.vector)(exports.CellInput);
|
|
97
|
+
exports.CellOutput = (0, codec_js_1.table)({
|
|
98
|
+
capacity: exports.Uint64,
|
|
99
|
+
lock: exports.Script,
|
|
100
|
+
type: exports.ScriptOpt,
|
|
75
101
|
}).map({ outMap: ckb.CellOutput.from });
|
|
76
|
-
|
|
77
|
-
|
|
102
|
+
exports.CellOutputVec = (0, codec_js_1.vector)(exports.CellOutput);
|
|
103
|
+
exports.DepType = codec_js_1.Codec.from({
|
|
78
104
|
byteLength: 1,
|
|
79
105
|
encode: ckb.depTypeToBytes,
|
|
80
106
|
decode: ckb.depTypeFromBytes,
|
|
81
107
|
});
|
|
82
|
-
|
|
83
|
-
outPoint: OutPoint,
|
|
84
|
-
depType: DepType,
|
|
108
|
+
exports.CellDep = (0, codec_js_1.struct)({
|
|
109
|
+
outPoint: exports.OutPoint,
|
|
110
|
+
depType: exports.DepType,
|
|
85
111
|
}).map({ outMap: ckb.CellDep.from });
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
version: Uint32,
|
|
89
|
-
cellDeps: CellDepVec,
|
|
90
|
-
headerDeps: Byte32Vec,
|
|
91
|
-
inputs: CellInputVec,
|
|
92
|
-
outputs: CellOutputVec,
|
|
93
|
-
outputsData: BytesVec,
|
|
94
|
-
witnesses: BytesVec,
|
|
112
|
+
exports.CellDepVec = (0, codec_js_1.vector)(exports.CellDep);
|
|
113
|
+
exports.Transaction = (0, codec_js_1.table)({
|
|
114
|
+
version: exports.Uint32,
|
|
115
|
+
cellDeps: exports.CellDepVec,
|
|
116
|
+
headerDeps: exports.Byte32Vec,
|
|
117
|
+
inputs: exports.CellInputVec,
|
|
118
|
+
outputs: exports.CellOutputVec,
|
|
119
|
+
outputsData: exports.BytesVec,
|
|
120
|
+
witnesses: exports.BytesVec,
|
|
95
121
|
}).map({ outMap: ckb.Transaction.from });
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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");
|
|
3
15
|
/**
|
|
4
16
|
* Get the min among all numbers.
|
|
5
17
|
* @public
|
|
@@ -12,7 +24,7 @@ import { hexFrom } from "../hex/index.js";
|
|
|
12
24
|
* numMin(1, 2, 3); // Outputs 1n
|
|
13
25
|
* ```
|
|
14
26
|
*/
|
|
15
|
-
|
|
27
|
+
function numMin(a, ...numbers) {
|
|
16
28
|
let min = numFrom(a);
|
|
17
29
|
numbers.forEach((nLike) => {
|
|
18
30
|
const n = numFrom(nLike);
|
|
@@ -34,7 +46,7 @@ export function numMin(a, ...numbers) {
|
|
|
34
46
|
* numMax(1, 2, 3); // Outputs 3n
|
|
35
47
|
* ```
|
|
36
48
|
*/
|
|
37
|
-
|
|
49
|
+
function numMax(a, ...numbers) {
|
|
38
50
|
let max = numFrom(a);
|
|
39
51
|
numbers.forEach((nLike) => {
|
|
40
52
|
const n = numFrom(nLike);
|
|
@@ -57,14 +69,14 @@ export function numMax(a, ...numbers) {
|
|
|
57
69
|
* const numFromHex = numFrom("0x3039"); // Outputs 12345n
|
|
58
70
|
* ```
|
|
59
71
|
*/
|
|
60
|
-
|
|
72
|
+
function numFrom(val) {
|
|
61
73
|
if (typeof val === "bigint") {
|
|
62
74
|
return val;
|
|
63
75
|
}
|
|
64
76
|
if (typeof val === "string" || typeof val === "number") {
|
|
65
77
|
return BigInt(val);
|
|
66
78
|
}
|
|
67
|
-
return BigInt(hexFrom(val));
|
|
79
|
+
return BigInt((0, index_js_2.hexFrom)(val));
|
|
68
80
|
}
|
|
69
81
|
/**
|
|
70
82
|
* Converts a NumLike value to a hexadecimal string.
|
|
@@ -78,7 +90,7 @@ export function numFrom(val) {
|
|
|
78
90
|
* const hex = numToHex(12345); // Outputs "0x3039"
|
|
79
91
|
* ```
|
|
80
92
|
*/
|
|
81
|
-
|
|
93
|
+
function numToHex(val) {
|
|
82
94
|
return `0x${numFrom(val).toString(16)}`;
|
|
83
95
|
}
|
|
84
96
|
/**
|
|
@@ -94,7 +106,7 @@ export function numToHex(val) {
|
|
|
94
106
|
* const bytes = numToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
|
|
95
107
|
* ```
|
|
96
108
|
*/
|
|
97
|
-
|
|
109
|
+
function numToBytes(val, bytes) {
|
|
98
110
|
return numLeToBytes(val, bytes);
|
|
99
111
|
}
|
|
100
112
|
/**
|
|
@@ -110,7 +122,7 @@ export function numToBytes(val, bytes) {
|
|
|
110
122
|
* const bytes = numLeToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
|
|
111
123
|
* ```
|
|
112
124
|
*/
|
|
113
|
-
|
|
125
|
+
function numLeToBytes(val, bytes) {
|
|
114
126
|
return numBeToBytes(val, bytes).reverse();
|
|
115
127
|
}
|
|
116
128
|
/**
|
|
@@ -126,12 +138,12 @@ export function numLeToBytes(val, bytes) {
|
|
|
126
138
|
* const bytes = numBeToBytes(12345, 4); // Outputs Uint8Array [0, 0, 48, 57]
|
|
127
139
|
* ```
|
|
128
140
|
*/
|
|
129
|
-
|
|
130
|
-
const rawBytes = bytesFrom(numFrom(val).toString(16));
|
|
141
|
+
function numBeToBytes(val, bytes) {
|
|
142
|
+
const rawBytes = (0, index_js_1.bytesFrom)(numFrom(val).toString(16));
|
|
131
143
|
if (bytes == null) {
|
|
132
144
|
return rawBytes;
|
|
133
145
|
}
|
|
134
|
-
return bytesConcat(Array.from(Array(bytes - rawBytes.length), () => 0), rawBytes);
|
|
146
|
+
return (0, index_js_1.bytesConcat)(Array.from(Array(bytes - rawBytes.length), () => 0), rawBytes);
|
|
135
147
|
}
|
|
136
148
|
/**
|
|
137
149
|
* Converts a byte array to a Num (bigint) assuming little-endian order.
|
|
@@ -145,7 +157,7 @@ export function numBeToBytes(val, bytes) {
|
|
|
145
157
|
* const num = numFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
|
|
146
158
|
* ```
|
|
147
159
|
*/
|
|
148
|
-
|
|
160
|
+
function numFromBytes(val) {
|
|
149
161
|
return numLeFromBytes(val);
|
|
150
162
|
}
|
|
151
163
|
/**
|
|
@@ -160,8 +172,8 @@ export function numFromBytes(val) {
|
|
|
160
172
|
* const num = numLeFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
|
|
161
173
|
* ```
|
|
162
174
|
*/
|
|
163
|
-
|
|
164
|
-
return numBeFromBytes([...bytesFrom(val)].reverse());
|
|
175
|
+
function numLeFromBytes(val) {
|
|
176
|
+
return numBeFromBytes([...(0, index_js_1.bytesFrom)(val)].reverse());
|
|
165
177
|
}
|
|
166
178
|
/**
|
|
167
179
|
* Converts a byte array to a Num (bigint) assuming big-endian order.
|
|
@@ -175,6 +187,6 @@ export function numLeFromBytes(val) {
|
|
|
175
187
|
* const num = numBeFromBytes(new Uint8Array([0, 0, 48, 57])); // Outputs 12345n
|
|
176
188
|
* ```
|
|
177
189
|
*/
|
|
178
|
-
|
|
179
|
-
return numFrom(bytesFrom(val));
|
|
190
|
+
function numBeFromBytes(val) {
|
|
191
|
+
return numFrom((0, index_js_1.bytesFrom)(val));
|
|
180
192
|
}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
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
|
+
};
|
|
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,23 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerBtc = void 0;
|
|
4
|
+
const index_js_1 = require("../../address/index.js");
|
|
5
|
+
const index_js_2 = require("../../bytes/index.js");
|
|
6
|
+
const index_js_3 = require("../../ckb/index.js");
|
|
7
|
+
const index_js_4 = require("../../client/index.js");
|
|
8
|
+
const index_js_5 = require("../../hex/index.js");
|
|
9
|
+
const index_js_6 = require("../../num/index.js");
|
|
10
|
+
const index_js_7 = require("../signer/index.js");
|
|
11
|
+
const verify_js_1 = require("./verify.js");
|
|
9
12
|
/**
|
|
10
13
|
* An abstract class extending the Signer class for Bitcoin-like signing operations.
|
|
11
14
|
* This class provides methods to get Bitcoin account, public key, and internal address,
|
|
12
15
|
* as well as signing transactions.
|
|
13
16
|
* @public
|
|
14
17
|
*/
|
|
15
|
-
|
|
18
|
+
class SignerBtc extends index_js_7.Signer {
|
|
16
19
|
get type() {
|
|
17
|
-
return SignerType.BTC;
|
|
20
|
+
return index_js_7.SignerType.BTC;
|
|
18
21
|
}
|
|
19
22
|
get signType() {
|
|
20
|
-
return SignerSignType.BtcEcdsa;
|
|
23
|
+
return index_js_7.SignerSignType.BtcEcdsa;
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
26
|
* Gets the internal address, which is the Bitcoin account in this case.
|
|
@@ -33,7 +36,7 @@ export class SignerBtc extends Signer {
|
|
|
33
36
|
* @returns A promise that resolves to a string representing the identity
|
|
34
37
|
*/
|
|
35
38
|
async getIdentity() {
|
|
36
|
-
return hexFrom(await this.getBtcPublicKey()).slice(2);
|
|
39
|
+
return (0, index_js_5.hexFrom)(await this.getBtcPublicKey()).slice(2);
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
42
|
* Gets an array of Address objects representing the known script addresses for the signer.
|
|
@@ -42,9 +45,9 @@ export class SignerBtc extends Signer {
|
|
|
42
45
|
*/
|
|
43
46
|
async getAddressObjs() {
|
|
44
47
|
const publicKey = await this.getBtcPublicKey();
|
|
45
|
-
const hash = btcEcdsaPublicKeyHash(publicKey);
|
|
48
|
+
const hash = (0, verify_js_1.btcEcdsaPublicKeyHash)(publicKey);
|
|
46
49
|
return [
|
|
47
|
-
await Address.fromKnownScript(this.client, KnownScript.OmniLock, hexFrom([0x04, ...hash, 0x00])),
|
|
50
|
+
await index_js_1.Address.fromKnownScript(this.client, index_js_4.KnownScript.OmniLock, (0, index_js_5.hexFrom)([0x04, ...hash, 0x00])),
|
|
48
51
|
];
|
|
49
52
|
}
|
|
50
53
|
/**
|
|
@@ -54,9 +57,9 @@ export class SignerBtc extends Signer {
|
|
|
54
57
|
* @returns A promise that resolves to the prepared Transaction object.
|
|
55
58
|
*/
|
|
56
59
|
async prepareTransaction(txLike) {
|
|
57
|
-
const tx = Transaction.from(txLike);
|
|
60
|
+
const tx = index_js_3.Transaction.from(txLike);
|
|
58
61
|
const { script } = await this.getRecommendedAddressObj();
|
|
59
|
-
await tx.addCellDepsOfKnownScripts(this.client, KnownScript.OmniLock);
|
|
62
|
+
await tx.addCellDepsOfKnownScripts(this.client, index_js_4.KnownScript.OmniLock);
|
|
60
63
|
await tx.prepareSighashAllWitness(script, 85, this.client);
|
|
61
64
|
return tx;
|
|
62
65
|
}
|
|
@@ -67,17 +70,18 @@ export class SignerBtc extends Signer {
|
|
|
67
70
|
* @returns A promise that resolves to a signed Transaction object.
|
|
68
71
|
*/
|
|
69
72
|
async signOnlyTransaction(txLike) {
|
|
70
|
-
const tx = Transaction.from(txLike);
|
|
73
|
+
const tx = index_js_3.Transaction.from(txLike);
|
|
71
74
|
const { script } = await this.getRecommendedAddressObj();
|
|
72
75
|
const info = await tx.getSignHashInfo(script, this.client);
|
|
73
76
|
if (!info) {
|
|
74
77
|
return tx;
|
|
75
78
|
}
|
|
76
|
-
const signature = bytesFrom(await this.signMessageRaw(`CKB (Bitcoin Layer) transaction: ${info.message}`), "base64");
|
|
79
|
+
const signature = (0, index_js_2.bytesFrom)(await this.signMessageRaw(`CKB (Bitcoin Layer) transaction: ${info.message}`), "base64");
|
|
77
80
|
signature[0] = 31 + ((signature[0] - 27) % 4);
|
|
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));
|
|
81
|
+
const witness = index_js_3.WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
82
|
+
witness.lock = (0, index_js_5.hexFrom)((0, index_js_2.bytesConcat)((0, index_js_6.numToBytes)(5 * 4 + signature.length, 4), (0, index_js_6.numToBytes)(4 * 4, 4), (0, index_js_6.numToBytes)(5 * 4 + signature.length, 4), (0, index_js_6.numToBytes)(5 * 4 + signature.length, 4), (0, index_js_6.numToBytes)(signature.length, 4), signature));
|
|
80
83
|
tx.setWitnessArgsAt(info.position, witness);
|
|
81
84
|
return tx;
|
|
82
85
|
}
|
|
83
86
|
}
|
|
87
|
+
exports.SignerBtc = SignerBtc;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerBtcPublicKeyReadonly = void 0;
|
|
4
|
+
const index_js_1 = require("../../hex/index.js");
|
|
5
|
+
const signerBtc_js_1 = require("./signerBtc.js");
|
|
3
6
|
/**
|
|
4
7
|
* A class extending SignerBtc that provides read-only access to a Bitcoin public key and account.
|
|
5
8
|
* This class does not support signing operations.
|
|
6
9
|
* @public
|
|
7
10
|
*/
|
|
8
|
-
|
|
11
|
+
class SignerBtcPublicKeyReadonly extends signerBtc_js_1.SignerBtc {
|
|
9
12
|
/**
|
|
10
13
|
* Creates an instance of SignerBtcPublicKeyReadonly.
|
|
11
14
|
*
|
|
@@ -16,7 +19,7 @@ export class SignerBtcPublicKeyReadonly extends SignerBtc {
|
|
|
16
19
|
constructor(client, account, publicKey) {
|
|
17
20
|
super(client);
|
|
18
21
|
this.account = account;
|
|
19
|
-
this.publicKey = hexFrom(publicKey);
|
|
22
|
+
this.publicKey = (0, index_js_1.hexFrom)(publicKey);
|
|
20
23
|
}
|
|
21
24
|
/**
|
|
22
25
|
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
@@ -59,3 +62,4 @@ export class SignerBtcPublicKeyReadonly extends SignerBtc {
|
|
|
59
62
|
return this.publicKey;
|
|
60
63
|
}
|
|
61
64
|
}
|
|
65
|
+
exports.SignerBtcPublicKeyReadonly = SignerBtcPublicKeyReadonly;
|
|
@@ -1,33 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.btcEcdsaPublicKeyHash = btcEcdsaPublicKeyHash;
|
|
7
|
+
exports.btcP2pkhAddressFromPublicKey = btcP2pkhAddressFromPublicKey;
|
|
8
|
+
exports.btcPublicKeyFromP2pkhAddress = btcPublicKeyFromP2pkhAddress;
|
|
9
|
+
exports.verifyMessageBtcEcdsa = verifyMessageBtcEcdsa;
|
|
10
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
11
|
+
const ripemd160_1 = require("@noble/hashes/ripemd160");
|
|
12
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
13
|
+
const bitcoinjs_message_1 = require("bitcoinjs-message");
|
|
14
|
+
const bs58check_1 = __importDefault(require("bs58check"));
|
|
15
|
+
const index_js_1 = require("../../bytes/index.js");
|
|
16
|
+
const index_js_2 = require("../../hex/index.js");
|
|
8
17
|
/**
|
|
9
18
|
* @public
|
|
10
19
|
*/
|
|
11
|
-
|
|
12
|
-
return ripemd160(sha256(bytesFrom(publicKey)));
|
|
20
|
+
function btcEcdsaPublicKeyHash(publicKey) {
|
|
21
|
+
return (0, ripemd160_1.ripemd160)((0, sha256_1.sha256)((0, index_js_1.bytesFrom)(publicKey)));
|
|
13
22
|
}
|
|
14
23
|
/**
|
|
15
24
|
* @public
|
|
16
25
|
*/
|
|
17
|
-
|
|
18
|
-
return
|
|
26
|
+
function btcP2pkhAddressFromPublicKey(publicKey, network) {
|
|
27
|
+
return bs58check_1.default.encode((0, index_js_1.bytesConcat)([network], btcEcdsaPublicKeyHash(publicKey)));
|
|
19
28
|
}
|
|
20
29
|
/**
|
|
21
30
|
* @public
|
|
22
31
|
*/
|
|
23
|
-
|
|
24
|
-
return hexFrom(
|
|
32
|
+
function btcPublicKeyFromP2pkhAddress(address) {
|
|
33
|
+
return (0, index_js_2.hexFrom)(bs58check_1.default.decode(address).slice(1));
|
|
25
34
|
}
|
|
26
35
|
/**
|
|
27
36
|
* @public
|
|
28
37
|
*/
|
|
29
|
-
|
|
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);
|
|
38
|
+
function verifyMessageBtcEcdsa(message, signature, publicKey) {
|
|
39
|
+
const challenge = typeof message === "string" ? message : (0, index_js_2.hexFrom)(message).slice(2);
|
|
40
|
+
const [_, ...rawSign] = (0, index_js_1.bytesFrom)(signature, "base64");
|
|
41
|
+
return secp256k1_1.secp256k1.verify((0, index_js_1.bytesFrom)(rawSign), (0, bitcoinjs_message_1.magicHash)(challenge), publicKey);
|
|
33
42
|
}
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
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
|
+
};
|
|
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,42 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerCkbPrivateKey = void 0;
|
|
4
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
5
|
+
const index_js_1 = require("../../bytes/index.js");
|
|
6
|
+
const index_js_2 = require("../../ckb/index.js");
|
|
7
|
+
const index_js_3 = require("../../hex/index.js");
|
|
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");
|
|
8
11
|
/**
|
|
9
12
|
* @public
|
|
10
13
|
*/
|
|
11
|
-
|
|
14
|
+
class SignerCkbPrivateKey extends signerCkbPublicKey_js_1.SignerCkbPublicKey {
|
|
12
15
|
constructor(client, privateKey) {
|
|
13
|
-
const pk = hexFrom(privateKey);
|
|
14
|
-
if (bytesFrom(pk).length !== 32) {
|
|
16
|
+
const pk = (0, index_js_3.hexFrom)(privateKey);
|
|
17
|
+
if ((0, index_js_1.bytesFrom)(pk).length !== 32) {
|
|
15
18
|
throw new Error("Private key must be 32 bytes!");
|
|
16
19
|
}
|
|
17
|
-
super(client, secp256k1.getPublicKey(bytesFrom(pk), true));
|
|
20
|
+
super(client, secp256k1_1.secp256k1.getPublicKey((0, index_js_1.bytesFrom)(pk), true));
|
|
18
21
|
this.privateKey = pk;
|
|
19
22
|
}
|
|
20
23
|
async _signMessage(message) {
|
|
21
|
-
const signature = secp256k1.sign(bytesFrom(message), bytesFrom(this.privateKey));
|
|
24
|
+
const signature = secp256k1_1.secp256k1.sign((0, index_js_1.bytesFrom)(message), (0, index_js_1.bytesFrom)(this.privateKey));
|
|
22
25
|
const { r, s, recovery } = signature;
|
|
23
|
-
return hexFrom(bytesConcat(numBeToBytes(r, 32), numBeToBytes(s, 32), numBeToBytes(recovery, 1)));
|
|
26
|
+
return (0, index_js_3.hexFrom)((0, index_js_1.bytesConcat)((0, index_js_4.numBeToBytes)(r, 32), (0, index_js_4.numBeToBytes)(s, 32), (0, index_js_4.numBeToBytes)(recovery, 1)));
|
|
24
27
|
}
|
|
25
28
|
async signMessageRaw(message) {
|
|
26
|
-
return this._signMessage(messageHashCkbSecp256k1(message));
|
|
29
|
+
return this._signMessage((0, verifyCkbSecp256k1_js_1.messageHashCkbSecp256k1)(message));
|
|
27
30
|
}
|
|
28
31
|
async signOnlyTransaction(txLike) {
|
|
29
|
-
const tx = Transaction.from(txLike);
|
|
32
|
+
const tx = index_js_2.Transaction.from(txLike);
|
|
30
33
|
for (const { script } of await this.getRelatedScripts(tx)) {
|
|
31
34
|
const info = await tx.getSignHashInfo(script, this.client);
|
|
32
35
|
if (!info) {
|
|
33
36
|
return tx;
|
|
34
37
|
}
|
|
35
38
|
const signature = await this._signMessage(info.message);
|
|
36
|
-
const witness = tx.getWitnessArgsAt(info.position) ?? WitnessArgs.from({});
|
|
39
|
+
const witness = tx.getWitnessArgsAt(info.position) ?? index_js_2.WitnessArgs.from({});
|
|
37
40
|
witness.lock = signature;
|
|
38
41
|
tx.setWitnessArgsAt(info.position, witness);
|
|
39
42
|
}
|
|
40
43
|
return tx;
|
|
41
44
|
}
|
|
42
45
|
}
|
|
46
|
+
exports.SignerCkbPrivateKey = SignerCkbPrivateKey;
|