@ckb-ccc/core 0.1.0-alpha.7 → 0.1.1

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.
Files changed (148) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/ckb/transactionLumos.d.ts +2 -1
  3. package/dist/ckb/transactionLumos.d.ts.map +1 -1
  4. package/dist/client/client.js +1 -1
  5. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  6. package/dist/signer/btc/signerBtc.js +2 -3
  7. package/dist/signer/btc/verify.d.ts +14 -1
  8. package/dist/signer/btc/verify.d.ts.map +1 -1
  9. package/dist/signer/btc/verify.js +22 -1
  10. package/dist/signer/doge/index.d.ts +5 -0
  11. package/dist/signer/doge/index.d.ts.map +1 -0
  12. package/dist/signer/doge/index.js +4 -0
  13. package/dist/signer/doge/signerDoge.d.ts +52 -0
  14. package/dist/signer/doge/signerDoge.d.ts.map +1 -0
  15. package/dist/signer/doge/signerDoge.js +82 -0
  16. package/dist/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
  17. package/dist/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
  18. package/dist/signer/doge/signerDogeAddressReadonly.js +45 -0
  19. package/dist/signer/doge/signerDogePrivateKey.d.ts +52 -0
  20. package/dist/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
  21. package/dist/signer/doge/signerDogePrivateKey.js +68 -0
  22. package/dist/signer/doge/verify.d.ts +6 -0
  23. package/dist/signer/doge/verify.d.ts.map +1 -0
  24. package/dist/signer/doge/verify.js +17 -0
  25. package/dist/signer/index.d.ts +1 -0
  26. package/dist/signer/index.d.ts.map +1 -1
  27. package/dist/signer/index.js +1 -0
  28. package/dist/signer/nostr/index.d.ts +1 -0
  29. package/dist/signer/nostr/index.d.ts.map +1 -1
  30. package/dist/signer/nostr/index.js +1 -0
  31. package/dist/signer/signer/index.d.ts +4 -2
  32. package/dist/signer/signer/index.d.ts.map +1 -1
  33. package/dist/signer/signer/index.js +5 -0
  34. package/dist.commonjs/address/address.advanced.js +23 -28
  35. package/dist.commonjs/address/advanced.js +1 -17
  36. package/dist.commonjs/address/index.js +11 -15
  37. package/dist.commonjs/advanced.js +2 -31
  38. package/dist.commonjs/advancedBarrel.js +5 -21
  39. package/dist.commonjs/barrel.js +12 -41
  40. package/dist.commonjs/bytes/advanced.js +1 -2
  41. package/dist.commonjs/bytes/index.js +7 -12
  42. package/dist.commonjs/ckb/advanced.js +3 -32
  43. package/dist.commonjs/ckb/index.js +3 -19
  44. package/dist.commonjs/ckb/molecule.advanced/generated.js +64 -131
  45. package/dist.commonjs/ckb/molecule.advanced/index.js +2 -19
  46. package/dist.commonjs/ckb/script.advanced.js +3 -6
  47. package/dist.commonjs/ckb/script.js +23 -53
  48. package/dist.commonjs/ckb/transaction.advanced.js +3 -6
  49. package/dist.commonjs/ckb/transaction.js +122 -163
  50. package/dist.commonjs/ckb/transactionLumos.d.ts +2 -1
  51. package/dist.commonjs/ckb/transactionLumos.d.ts.map +1 -1
  52. package/dist.commonjs/ckb/transactionLumos.js +1 -2
  53. package/dist.commonjs/client/advanced.js +6 -22
  54. package/dist.commonjs/client/cache/advanced.js +1 -17
  55. package/dist.commonjs/client/cache/cache.js +3 -7
  56. package/dist.commonjs/client/cache/index.js +2 -18
  57. package/dist.commonjs/client/cache/memory.advanced.js +21 -28
  58. package/dist.commonjs/client/cache/memory.js +19 -23
  59. package/dist.commonjs/client/client.js +22 -26
  60. package/dist.commonjs/client/clientPublicMainnet.advanced.js +22 -25
  61. package/dist.commonjs/client/clientPublicMainnet.js +8 -15
  62. package/dist.commonjs/client/clientPublicTestnet.advanced.js +22 -25
  63. package/dist.commonjs/client/clientPublicTestnet.js +8 -15
  64. package/dist.commonjs/client/clientTypes.advanced.js +3 -6
  65. package/dist.commonjs/client/clientTypes.js +29 -43
  66. package/dist.commonjs/client/index.js +6 -22
  67. package/dist.commonjs/client/jsonRpc/advanced.js +2 -18
  68. package/dist.commonjs/client/jsonRpc/index.js +37 -41
  69. package/dist.commonjs/client/jsonRpc/transformers.js +57 -61
  70. package/dist.commonjs/client/jsonRpc/types.js +1 -2
  71. package/dist.commonjs/client/transports/advanced.js +8 -25
  72. package/dist.commonjs/client/transports/http.js +1 -5
  73. package/dist.commonjs/client/transports/transport.js +1 -2
  74. package/dist.commonjs/client/transports/webSocket.js +3 -10
  75. package/dist.commonjs/fixedPoint/index.js +4 -9
  76. package/dist.commonjs/hasher/advanced.js +1 -4
  77. package/dist.commonjs/hasher/hasher.js +1 -2
  78. package/dist.commonjs/hasher/hasherCkb.js +14 -20
  79. package/dist.commonjs/hasher/hasherKeecak256.js +7 -11
  80. package/dist.commonjs/hasher/index.js +3 -19
  81. package/dist.commonjs/hex/index.js +3 -6
  82. package/dist.commonjs/index.js +2 -31
  83. package/dist.commonjs/keystore/index.js +21 -25
  84. package/dist.commonjs/molecule/codec.js +48 -63
  85. package/dist.commonjs/molecule/index.js +2 -18
  86. package/dist.commonjs/molecule/predefined.js +77 -103
  87. package/dist.commonjs/num/index.js +17 -29
  88. package/dist.commonjs/signer/btc/index.js +3 -19
  89. package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
  90. package/dist.commonjs/signer/btc/signerBtc.js +20 -25
  91. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +4 -8
  92. package/dist.commonjs/signer/btc/verify.d.ts +14 -1
  93. package/dist.commonjs/signer/btc/verify.d.ts.map +1 -1
  94. package/dist.commonjs/signer/btc/verify.js +29 -11
  95. package/dist.commonjs/signer/ckb/index.js +5 -21
  96. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +16 -20
  97. package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +20 -24
  98. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +8 -12
  99. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +12 -16
  100. package/dist.commonjs/signer/ckb/verifyJoyId.js +5 -8
  101. package/dist.commonjs/signer/doge/index.d.ts +5 -0
  102. package/dist.commonjs/signer/doge/index.d.ts.map +1 -0
  103. package/dist.commonjs/signer/doge/index.js +4 -0
  104. package/dist.commonjs/signer/doge/signerDoge.d.ts +52 -0
  105. package/dist.commonjs/signer/doge/signerDoge.d.ts.map +1 -0
  106. package/dist.commonjs/signer/doge/signerDoge.js +82 -0
  107. package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
  108. package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
  109. package/dist.commonjs/signer/doge/signerDogeAddressReadonly.js +45 -0
  110. package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts +52 -0
  111. package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
  112. package/dist.commonjs/signer/doge/signerDogePrivateKey.js +68 -0
  113. package/dist.commonjs/signer/doge/verify.d.ts +6 -0
  114. package/dist.commonjs/signer/doge/verify.d.ts.map +1 -0
  115. package/dist.commonjs/signer/doge/verify.js +17 -0
  116. package/dist.commonjs/signer/dummy/alwaysError.js +2 -6
  117. package/dist.commonjs/signer/dummy/dummy.js +3 -7
  118. package/dist.commonjs/signer/dummy/index.js +3 -19
  119. package/dist.commonjs/signer/dummy/openLink.js +2 -6
  120. package/dist.commonjs/signer/evm/index.js +3 -19
  121. package/dist.commonjs/signer/evm/signerEvm.js +31 -35
  122. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +4 -8
  123. package/dist.commonjs/signer/evm/verify.js +4 -7
  124. package/dist.commonjs/signer/index.d.ts +1 -0
  125. package/dist.commonjs/signer/index.d.ts.map +1 -1
  126. package/dist.commonjs/signer/index.js +7 -22
  127. package/dist.commonjs/signer/nostr/index.d.ts +1 -0
  128. package/dist.commonjs/signer/nostr/index.d.ts.map +1 -1
  129. package/dist.commonjs/signer/nostr/index.js +2 -17
  130. package/dist.commonjs/signer/nostr/signerNostr.js +21 -25
  131. package/dist.commonjs/signer/nostr/verify.js +12 -16
  132. package/dist.commonjs/signer/signer/index.d.ts +4 -2
  133. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  134. package/dist.commonjs/signer/signer/index.js +22 -23
  135. package/dist.commonjs/utils/index.js +6 -12
  136. package/package.json +8 -1
  137. package/src/ckb/transactionLumos.ts +2 -1
  138. package/src/client/client.ts +1 -1
  139. package/src/signer/btc/signerBtc.ts +2 -3
  140. package/src/signer/btc/verify.ts +31 -2
  141. package/src/signer/doge/index.ts +4 -0
  142. package/src/signer/doge/signerDoge.ts +116 -0
  143. package/src/signer/doge/signerDogeAddressReadonly.ts +52 -0
  144. package/src/signer/doge/signerDogePrivateKey.ts +97 -0
  145. package/src/signer/doge/verify.ts +38 -0
  146. package/src/signer/index.ts +1 -0
  147. package/src/signer/nostr/index.ts +1 -0
  148. package/src/signer/signer/index.ts +9 -0
@@ -1,121 +1,95 @@
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;
1
+ import { bytesFrom, bytesTo } from "../bytes/index.js";
2
+ import * as ckb from "../ckb/index.js";
3
+ import { hexFrom } from "../hex/index.js";
4
+ import { byteVec, Codec, option, struct, table, uint, uintNumber, vector, } from "./codec.js";
5
+ export const Uint8 = uintNumber(1, true);
6
+ export const Uint16LE = uintNumber(2, true);
7
+ export const Uint16BE = uintNumber(2);
8
+ export const Uint16 = Uint16LE;
9
+ export const Uint32LE = uintNumber(4, true);
10
+ export const Uint32BE = uintNumber(4);
11
+ export const Uint32 = Uint32LE;
12
+ export const Uint64LE = uint(8, true);
13
+ export const Uint64BE = uint(8);
14
+ export const Uint64 = Uint64LE;
15
+ export const Uint128LE = uint(16, true);
16
+ export const Uint128BE = uint(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),
17
34
  });
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({
35
+ export const BytesOpt = option(Bytes);
36
+ export const BytesVec = vector(Bytes);
37
+ export const Byte32 = Codec.from({
64
38
  byteLength: 32,
65
- encode: (value) => (0, index_js_1.bytesFrom)(value),
66
- decode: (buffer) => (0, index_js_2.hexFrom)(buffer),
39
+ encode: (value) => bytesFrom(value),
40
+ decode: (buffer) => hexFrom(buffer),
67
41
  });
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"),
42
+ export const Byte32Opt = option(Byte32);
43
+ export const Byte32Vec = vector(Byte32);
44
+ export const String = byteVec({
45
+ encode: (value) => bytesFrom(value, "utf8"),
46
+ decode: (buffer) => bytesTo(buffer, "utf8"),
73
47
  });
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({
48
+ export const StringVec = vector(String);
49
+ export const StringOpt = option(String);
50
+ export const Hash = Byte32;
51
+ export const HashType = Codec.from({
78
52
  byteLength: 1,
79
53
  encode: ckb.hashTypeToBytes,
80
54
  decode: ckb.hashTypeFromBytes,
81
55
  });
82
- exports.Script = (0, codec_js_1.table)({
83
- codeHash: exports.Hash,
84
- hashType: exports.HashType,
85
- args: exports.Bytes,
56
+ export const Script = table({
57
+ codeHash: Hash,
58
+ hashType: HashType,
59
+ args: Bytes,
86
60
  }).map({ outMap: ckb.Script.from });
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,
61
+ export const ScriptOpt = option(Script);
62
+ export const OutPoint = struct({
63
+ txHash: Hash,
64
+ index: Uint32,
91
65
  }).map({ outMap: ckb.OutPoint.from });
92
- exports.CellInput = (0, codec_js_1.struct)({
93
- previousOutput: exports.OutPoint,
94
- since: exports.Uint64,
66
+ export const CellInput = struct({
67
+ previousOutput: OutPoint,
68
+ since: Uint64,
95
69
  }).map({ outMap: ckb.CellInput.from });
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,
70
+ export const CellInputVec = vector(CellInput);
71
+ export const CellOutput = table({
72
+ capacity: Uint64,
73
+ lock: Script,
74
+ type: ScriptOpt,
101
75
  }).map({ outMap: ckb.CellOutput.from });
102
- exports.CellOutputVec = (0, codec_js_1.vector)(exports.CellOutput);
103
- exports.DepType = codec_js_1.Codec.from({
76
+ export const CellOutputVec = vector(CellOutput);
77
+ export const DepType = Codec.from({
104
78
  byteLength: 1,
105
79
  encode: ckb.depTypeToBytes,
106
80
  decode: ckb.depTypeFromBytes,
107
81
  });
108
- exports.CellDep = (0, codec_js_1.struct)({
109
- outPoint: exports.OutPoint,
110
- depType: exports.DepType,
82
+ export const CellDep = struct({
83
+ outPoint: OutPoint,
84
+ depType: DepType,
111
85
  }).map({ outMap: ckb.CellDep.from });
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,
86
+ export const CellDepVec = vector(CellDep);
87
+ export const Transaction = table({
88
+ version: Uint32,
89
+ cellDeps: CellDepVec,
90
+ headerDeps: Byte32Vec,
91
+ inputs: CellInputVec,
92
+ outputs: CellOutputVec,
93
+ outputsData: BytesVec,
94
+ witnesses: BytesVec,
121
95
  }).map({ outMap: ckb.Transaction.from });
@@ -1,17 +1,5 @@
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");
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((0, index_js_2.hexFrom)(val));
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 = (0, index_js_1.bytesFrom)(numFrom(val).toString(16));
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 (0, index_js_1.bytesConcat)(Array.from(Array(bytes - rawBytes.length), () => 0), rawBytes);
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([...(0, index_js_1.bytesFrom)(val)].reverse());
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((0, index_js_1.bytesFrom)(val));
178
+ export function numBeFromBytes(val) {
179
+ return numFrom(bytesFrom(val));
192
180
  }
@@ -1,19 +1,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
+ 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":"AAEA,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;AAExE;;;;;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
+ {"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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SignerBtc = void 0;
4
- const ripemd160_1 = require("@noble/hashes/ripemd160");
5
- const sha256_1 = require("@noble/hashes/sha256");
6
- const index_js_1 = require("../../address/index.js");
7
- const index_js_2 = require("../../bytes/index.js");
8
- const index_js_3 = require("../../ckb/index.js");
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 index_js_7.Signer {
15
+ export class SignerBtc extends Signer {
20
16
  get type() {
21
- return index_js_7.SignerType.BTC;
17
+ return SignerType.BTC;
22
18
  }
23
19
  get signType() {
24
- return index_js_7.SignerSignType.BtcEcdsa;
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 (0, index_js_5.hexFrom)(await this.getBtcPublicKey()).slice(2);
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 = (0, ripemd160_1.ripemd160)((0, sha256_1.sha256)((0, index_js_2.bytesFrom)(publicKey)));
45
+ const hash = btcEcdsaPublicKeyHash(publicKey);
50
46
  return [
51
- await index_js_1.Address.fromKnownScript(this.client, index_js_4.KnownScript.OmniLock, (0, index_js_5.hexFrom)([0x04, ...hash, 0x00])),
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 = index_js_3.Transaction.from(txLike);
57
+ const tx = Transaction.from(txLike);
62
58
  const { script } = await this.getRecommendedAddressObj();
63
- await tx.addCellDepsOfKnownScripts(this.client, index_js_4.KnownScript.OmniLock);
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 = index_js_3.Transaction.from(txLike);
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 = (0, index_js_2.bytesFrom)(await this.signMessageRaw(`CKB (Bitcoin Layer) transaction: ${info.message}`), "base64");
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 = index_js_3.WitnessArgs.fromBytes(tx.witnesses[info.position]);
83
- 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));
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
- "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");
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 signerBtc_js_1.SignerBtc {
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 = (0, index_js_1.hexFrom)(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":"AAEA,OAAO,EAAE,SAAS,EAAa,MAAM,sBAAsB,CAAC;AAG5D;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAOT"}
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyMessageBtcEcdsa = verifyMessageBtcEcdsa;
4
- const secp256k1_1 = require("@noble/curves/secp256k1");
5
- const bitcoinjs_message_1 = require("bitcoinjs-message");
6
- const index_js_1 = require("../../bytes/index.js");
7
- const index_js_2 = require("../../hex/index.js");
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 verifyMessageBtcEcdsa(message, signature, publicKey) {
12
- const challenge = typeof message === "string" ? message : (0, index_js_2.hexFrom)(message).slice(2);
13
- const [_, ...rawSign] = (0, index_js_1.bytesFrom)(signature, "base64");
14
- return secp256k1_1.secp256k1.verify((0, index_js_1.bytesFrom)(rawSign), (0, bitcoinjs_message_1.magicHash)(challenge), publicKey);
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
- "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
+ 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
- "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");
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 signerCkbPublicKey_js_1.SignerCkbPublicKey {
11
+ export class SignerCkbPrivateKey extends SignerCkbPublicKey {
15
12
  constructor(client, privateKey) {
16
- const pk = (0, index_js_3.hexFrom)(privateKey);
17
- if ((0, index_js_1.bytesFrom)(pk).length !== 32) {
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, secp256k1_1.secp256k1.getPublicKey((0, index_js_1.bytesFrom)(pk), true));
17
+ super(client, secp256k1.getPublicKey(bytesFrom(pk), true));
21
18
  this.privateKey = pk;
22
19
  }
23
20
  async _signMessage(message) {
24
- const signature = secp256k1_1.secp256k1.sign((0, index_js_1.bytesFrom)(message), (0, index_js_1.bytesFrom)(this.privateKey));
21
+ const signature = secp256k1.sign(bytesFrom(message), bytesFrom(this.privateKey));
25
22
  const { r, s, recovery } = signature;
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)));
23
+ return hexFrom(bytesConcat(numBeToBytes(r, 32), numBeToBytes(s, 32), numBeToBytes(recovery, 1)));
27
24
  }
28
25
  async signMessageRaw(message) {
29
- return this._signMessage((0, verifyCkbSecp256k1_js_1.messageHashCkbSecp256k1)(message));
26
+ return this._signMessage(messageHashCkbSecp256k1(message));
30
27
  }
31
28
  async signOnlyTransaction(txLike) {
32
- const tx = index_js_2.Transaction.from(txLike);
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) ?? index_js_2.WitnessArgs.from({});
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;