@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.
Files changed (172) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/barrel.d.ts +1 -0
  3. package/dist/barrel.d.ts.map +1 -1
  4. package/dist/barrel.js +1 -0
  5. package/dist/ckb/transactionLumos.d.ts +2 -1
  6. package/dist/ckb/transactionLumos.d.ts.map +1 -1
  7. package/dist/client/client.js +1 -1
  8. package/dist/molecule/codec.d.ts +118 -0
  9. package/dist/molecule/codec.d.ts.map +1 -0
  10. package/dist/molecule/codec.js +446 -0
  11. package/dist/molecule/index.d.ts +3 -0
  12. package/dist/molecule/index.d.ts.map +1 -0
  13. package/dist/molecule/index.js +2 -0
  14. package/dist/molecule/predefined.d.ts +52 -0
  15. package/dist/molecule/predefined.d.ts.map +1 -0
  16. package/dist/molecule/predefined.js +95 -0
  17. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  18. package/dist/signer/btc/signerBtc.js +2 -3
  19. package/dist/signer/btc/verify.d.ts +14 -1
  20. package/dist/signer/btc/verify.d.ts.map +1 -1
  21. package/dist/signer/btc/verify.js +22 -1
  22. package/dist/signer/doge/index.d.ts +5 -0
  23. package/dist/signer/doge/index.d.ts.map +1 -0
  24. package/dist/signer/doge/index.js +4 -0
  25. package/dist/signer/doge/signerDoge.d.ts +52 -0
  26. package/dist/signer/doge/signerDoge.d.ts.map +1 -0
  27. package/dist/signer/doge/signerDoge.js +82 -0
  28. package/dist/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
  29. package/dist/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
  30. package/dist/signer/doge/signerDogeAddressReadonly.js +45 -0
  31. package/dist/signer/doge/signerDogePrivateKey.d.ts +52 -0
  32. package/dist/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
  33. package/dist/signer/doge/signerDogePrivateKey.js +68 -0
  34. package/dist/signer/doge/verify.d.ts +6 -0
  35. package/dist/signer/doge/verify.d.ts.map +1 -0
  36. package/dist/signer/doge/verify.js +17 -0
  37. package/dist/signer/index.d.ts +1 -0
  38. package/dist/signer/index.d.ts.map +1 -1
  39. package/dist/signer/index.js +1 -0
  40. package/dist/signer/nostr/index.d.ts +1 -0
  41. package/dist/signer/nostr/index.d.ts.map +1 -1
  42. package/dist/signer/nostr/index.js +1 -0
  43. package/dist/signer/signer/index.d.ts +4 -2
  44. package/dist/signer/signer/index.d.ts.map +1 -1
  45. package/dist/signer/signer/index.js +5 -0
  46. package/dist.commonjs/address/address.advanced.js +23 -28
  47. package/dist.commonjs/address/advanced.js +1 -17
  48. package/dist.commonjs/address/index.js +11 -15
  49. package/dist.commonjs/advanced.js +2 -31
  50. package/dist.commonjs/advancedBarrel.js +5 -21
  51. package/dist.commonjs/barrel.d.ts +1 -0
  52. package/dist.commonjs/barrel.d.ts.map +1 -1
  53. package/dist.commonjs/barrel.js +12 -27
  54. package/dist.commonjs/bytes/advanced.js +1 -2
  55. package/dist.commonjs/bytes/index.js +7 -12
  56. package/dist.commonjs/ckb/advanced.js +3 -32
  57. package/dist.commonjs/ckb/index.js +3 -19
  58. package/dist.commonjs/ckb/molecule.advanced/generated.js +64 -131
  59. package/dist.commonjs/ckb/molecule.advanced/index.js +2 -19
  60. package/dist.commonjs/ckb/script.advanced.js +3 -6
  61. package/dist.commonjs/ckb/script.js +23 -53
  62. package/dist.commonjs/ckb/transaction.advanced.js +3 -6
  63. package/dist.commonjs/ckb/transaction.js +122 -163
  64. package/dist.commonjs/ckb/transactionLumos.d.ts +2 -1
  65. package/dist.commonjs/ckb/transactionLumos.d.ts.map +1 -1
  66. package/dist.commonjs/ckb/transactionLumos.js +1 -2
  67. package/dist.commonjs/client/advanced.js +6 -22
  68. package/dist.commonjs/client/cache/advanced.js +1 -17
  69. package/dist.commonjs/client/cache/cache.js +3 -7
  70. package/dist.commonjs/client/cache/index.js +2 -18
  71. package/dist.commonjs/client/cache/memory.advanced.js +21 -28
  72. package/dist.commonjs/client/cache/memory.js +19 -23
  73. package/dist.commonjs/client/client.js +22 -26
  74. package/dist.commonjs/client/clientPublicMainnet.advanced.js +22 -25
  75. package/dist.commonjs/client/clientPublicMainnet.js +8 -15
  76. package/dist.commonjs/client/clientPublicTestnet.advanced.js +22 -25
  77. package/dist.commonjs/client/clientPublicTestnet.js +8 -15
  78. package/dist.commonjs/client/clientTypes.advanced.js +3 -6
  79. package/dist.commonjs/client/clientTypes.js +29 -43
  80. package/dist.commonjs/client/index.js +6 -22
  81. package/dist.commonjs/client/jsonRpc/advanced.js +2 -18
  82. package/dist.commonjs/client/jsonRpc/index.js +37 -41
  83. package/dist.commonjs/client/jsonRpc/transformers.js +57 -61
  84. package/dist.commonjs/client/jsonRpc/types.js +1 -2
  85. package/dist.commonjs/client/transports/advanced.js +8 -25
  86. package/dist.commonjs/client/transports/http.js +1 -5
  87. package/dist.commonjs/client/transports/transport.js +1 -2
  88. package/dist.commonjs/client/transports/webSocket.js +3 -10
  89. package/dist.commonjs/fixedPoint/index.js +4 -9
  90. package/dist.commonjs/hasher/advanced.js +1 -4
  91. package/dist.commonjs/hasher/hasher.js +1 -2
  92. package/dist.commonjs/hasher/hasherCkb.js +14 -20
  93. package/dist.commonjs/hasher/hasherKeecak256.js +7 -11
  94. package/dist.commonjs/hasher/index.js +3 -19
  95. package/dist.commonjs/hex/index.js +3 -6
  96. package/dist.commonjs/index.js +2 -31
  97. package/dist.commonjs/keystore/index.js +21 -25
  98. package/dist.commonjs/molecule/codec.d.ts +118 -0
  99. package/dist.commonjs/molecule/codec.d.ts.map +1 -0
  100. package/dist.commonjs/molecule/codec.js +446 -0
  101. package/dist.commonjs/molecule/index.d.ts +3 -0
  102. package/dist.commonjs/molecule/index.d.ts.map +1 -0
  103. package/dist.commonjs/molecule/index.js +2 -0
  104. package/dist.commonjs/molecule/predefined.d.ts +52 -0
  105. package/dist.commonjs/molecule/predefined.d.ts.map +1 -0
  106. package/dist.commonjs/molecule/predefined.js +95 -0
  107. package/dist.commonjs/num/index.js +17 -29
  108. package/dist.commonjs/signer/btc/index.js +3 -19
  109. package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
  110. package/dist.commonjs/signer/btc/signerBtc.js +20 -25
  111. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +4 -8
  112. package/dist.commonjs/signer/btc/verify.d.ts +14 -1
  113. package/dist.commonjs/signer/btc/verify.d.ts.map +1 -1
  114. package/dist.commonjs/signer/btc/verify.js +29 -11
  115. package/dist.commonjs/signer/ckb/index.js +5 -21
  116. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +16 -20
  117. package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +20 -24
  118. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +8 -12
  119. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +12 -16
  120. package/dist.commonjs/signer/ckb/verifyJoyId.js +5 -8
  121. package/dist.commonjs/signer/doge/index.d.ts +5 -0
  122. package/dist.commonjs/signer/doge/index.d.ts.map +1 -0
  123. package/dist.commonjs/signer/doge/index.js +4 -0
  124. package/dist.commonjs/signer/doge/signerDoge.d.ts +52 -0
  125. package/dist.commonjs/signer/doge/signerDoge.d.ts.map +1 -0
  126. package/dist.commonjs/signer/doge/signerDoge.js +82 -0
  127. package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
  128. package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
  129. package/dist.commonjs/signer/doge/signerDogeAddressReadonly.js +45 -0
  130. package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts +52 -0
  131. package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
  132. package/dist.commonjs/signer/doge/signerDogePrivateKey.js +68 -0
  133. package/dist.commonjs/signer/doge/verify.d.ts +6 -0
  134. package/dist.commonjs/signer/doge/verify.d.ts.map +1 -0
  135. package/dist.commonjs/signer/doge/verify.js +17 -0
  136. package/dist.commonjs/signer/dummy/alwaysError.js +2 -6
  137. package/dist.commonjs/signer/dummy/dummy.js +3 -7
  138. package/dist.commonjs/signer/dummy/index.js +3 -19
  139. package/dist.commonjs/signer/dummy/openLink.js +2 -6
  140. package/dist.commonjs/signer/evm/index.js +3 -19
  141. package/dist.commonjs/signer/evm/signerEvm.js +31 -35
  142. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +4 -8
  143. package/dist.commonjs/signer/evm/verify.js +4 -7
  144. package/dist.commonjs/signer/index.d.ts +1 -0
  145. package/dist.commonjs/signer/index.d.ts.map +1 -1
  146. package/dist.commonjs/signer/index.js +7 -22
  147. package/dist.commonjs/signer/nostr/index.d.ts +1 -0
  148. package/dist.commonjs/signer/nostr/index.d.ts.map +1 -1
  149. package/dist.commonjs/signer/nostr/index.js +2 -17
  150. package/dist.commonjs/signer/nostr/signerNostr.js +21 -25
  151. package/dist.commonjs/signer/nostr/verify.js +12 -16
  152. package/dist.commonjs/signer/signer/index.d.ts +4 -2
  153. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  154. package/dist.commonjs/signer/signer/index.js +22 -23
  155. package/dist.commonjs/utils/index.js +6 -12
  156. package/package.json +3 -1
  157. package/src/barrel.ts +1 -0
  158. package/src/ckb/transactionLumos.ts +2 -1
  159. package/src/client/client.ts +1 -1
  160. package/src/molecule/codec.ts +610 -0
  161. package/src/molecule/index.ts +2 -0
  162. package/src/molecule/predefined.ts +114 -0
  163. package/src/signer/btc/signerBtc.ts +2 -3
  164. package/src/signer/btc/verify.ts +31 -2
  165. package/src/signer/doge/index.ts +4 -0
  166. package/src/signer/doge/signerDoge.ts +116 -0
  167. package/src/signer/doge/signerDogeAddressReadonly.ts +52 -0
  168. package/src/signer/doge/signerDogePrivateKey.ts +97 -0
  169. package/src/signer/doge/verify.ts +38 -0
  170. package/src/signer/index.ts +1 -0
  171. package/src/signer/nostr/index.ts +1 -0
  172. package/src/signer/signer/index.ts +9 -0
@@ -0,0 +1,2 @@
1
+ export * from "./codec.js";
2
+ export * from "./predefined.js";
@@ -0,0 +1,52 @@
1
+ import * as ckb from "../ckb/index.js";
2
+ import { Hex, HexLike } from "../hex/index.js";
3
+ import { Codec } from "./codec.js";
4
+ export declare const Uint8: Codec<import("../barrel.js").NumLike, number>;
5
+ export declare const Uint16LE: Codec<import("../barrel.js").NumLike, number>;
6
+ export declare const Uint16BE: Codec<import("../barrel.js").NumLike, number>;
7
+ export declare const Uint16: Codec<import("../barrel.js").NumLike, number>;
8
+ export declare const Uint32LE: Codec<import("../barrel.js").NumLike, number>;
9
+ export declare const Uint32BE: Codec<import("../barrel.js").NumLike, number>;
10
+ export declare const Uint32: Codec<import("../barrel.js").NumLike, number>;
11
+ export declare const Uint64LE: Codec<import("../barrel.js").NumLike, bigint>;
12
+ export declare const Uint64BE: Codec<import("../barrel.js").NumLike, bigint>;
13
+ export declare const Uint64: Codec<import("../barrel.js").NumLike, bigint>;
14
+ export declare const Uint128LE: Codec<import("../barrel.js").NumLike, bigint>;
15
+ export declare const Uint128BE: Codec<import("../barrel.js").NumLike, bigint>;
16
+ export declare const Uint128: Codec<import("../barrel.js").NumLike, bigint>;
17
+ export declare const Uint256LE: Codec<import("../barrel.js").NumLike, bigint>;
18
+ export declare const Uint256BE: Codec<import("../barrel.js").NumLike, bigint>;
19
+ export declare const Uint256: Codec<import("../barrel.js").NumLike, bigint>;
20
+ export declare const Uint512LE: Codec<import("../barrel.js").NumLike, bigint>;
21
+ export declare const Uint512BE: Codec<import("../barrel.js").NumLike, bigint>;
22
+ export declare const Uint512: Codec<import("../barrel.js").NumLike, bigint>;
23
+ export declare const Uint8Opt: Codec<import("../barrel.js").NumLike | null | undefined, number | undefined>;
24
+ export declare const Uint16Opt: Codec<import("../barrel.js").NumLike | null | undefined, number | undefined>;
25
+ export declare const Uint32Opt: Codec<import("../barrel.js").NumLike | null | undefined, number | undefined>;
26
+ export declare const Uint64Opt: Codec<import("../barrel.js").NumLike | null | undefined, bigint | undefined>;
27
+ export declare const Uint128Opt: Codec<import("../barrel.js").NumLike | null | undefined, bigint | undefined>;
28
+ export declare const Uint256Opt: Codec<import("../barrel.js").NumLike | null | undefined, bigint | undefined>;
29
+ export declare const Uint512Opt: Codec<import("../barrel.js").NumLike | null | undefined, bigint | undefined>;
30
+ export declare const Bytes: Codec<HexLike, Hex>;
31
+ export declare const BytesOpt: Codec<import("../bytes/index.js").BytesLike | null | undefined, `0x${string}` | undefined>;
32
+ export declare const BytesVec: Codec<import("../bytes/index.js").BytesLike[], `0x${string}`[]>;
33
+ export declare const Byte32: Codec<HexLike, Hex>;
34
+ export declare const Byte32Opt: Codec<import("../bytes/index.js").BytesLike | null | undefined, `0x${string}` | undefined>;
35
+ export declare const Byte32Vec: Codec<import("../bytes/index.js").BytesLike[], `0x${string}`[]>;
36
+ export declare const String: Codec<string, string>;
37
+ export declare const StringVec: Codec<string[], string[]>;
38
+ export declare const StringOpt: Codec<string | null | undefined, string | undefined>;
39
+ export declare const Hash: Codec<import("../bytes/index.js").BytesLike, `0x${string}`>;
40
+ export declare const HashType: Codec<ckb.HashTypeLike, ckb.HashType>;
41
+ export declare const Script: Codec<ckb.ScriptLike, ckb.Script>;
42
+ export declare const ScriptOpt: Codec<ckb.ScriptLike | null | undefined, ckb.Script | undefined>;
43
+ export declare const OutPoint: Codec<ckb.OutPointLike, ckb.OutPoint>;
44
+ export declare const CellInput: Codec<ckb.CellInputLike, ckb.CellInput>;
45
+ export declare const CellInputVec: Codec<ckb.CellInputLike[], ckb.CellInput[]>;
46
+ export declare const CellOutput: Codec<ckb.CellOutputLike, ckb.CellOutput>;
47
+ export declare const CellOutputVec: Codec<ckb.CellOutputLike[], ckb.CellOutput[]>;
48
+ export declare const DepType: Codec<ckb.DepTypeLike, ckb.DepType>;
49
+ export declare const CellDep: Codec<ckb.CellDepLike, ckb.CellDep>;
50
+ export declare const CellDepVec: Codec<ckb.CellDepLike[], ckb.CellDep[]>;
51
+ export declare const Transaction: Codec<ckb.TransactionLike, ckb.Transaction>;
52
+ //# sourceMappingURL=predefined.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predefined.d.ts","sourceRoot":"","sources":["../../src/molecule/predefined.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,95 @@
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),
34
+ });
35
+ export const BytesOpt = option(Bytes);
36
+ export const BytesVec = vector(Bytes);
37
+ export const Byte32 = Codec.from({
38
+ byteLength: 32,
39
+ encode: (value) => bytesFrom(value),
40
+ decode: (buffer) => hexFrom(buffer),
41
+ });
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"),
47
+ });
48
+ export const StringVec = vector(String);
49
+ export const StringOpt = option(String);
50
+ export const Hash = Byte32;
51
+ export const HashType = Codec.from({
52
+ byteLength: 1,
53
+ encode: ckb.hashTypeToBytes,
54
+ decode: ckb.hashTypeFromBytes,
55
+ });
56
+ export const Script = table({
57
+ codeHash: Hash,
58
+ hashType: HashType,
59
+ args: Bytes,
60
+ }).map({ outMap: ckb.Script.from });
61
+ export const ScriptOpt = option(Script);
62
+ export const OutPoint = struct({
63
+ txHash: Hash,
64
+ index: Uint32,
65
+ }).map({ outMap: ckb.OutPoint.from });
66
+ export const CellInput = struct({
67
+ previousOutput: OutPoint,
68
+ since: Uint64,
69
+ }).map({ outMap: ckb.CellInput.from });
70
+ export const CellInputVec = vector(CellInput);
71
+ export const CellOutput = table({
72
+ capacity: Uint64,
73
+ lock: Script,
74
+ type: ScriptOpt,
75
+ }).map({ outMap: ckb.CellOutput.from });
76
+ export const CellOutputVec = vector(CellOutput);
77
+ export const DepType = Codec.from({
78
+ byteLength: 1,
79
+ encode: ckb.depTypeToBytes,
80
+ decode: ckb.depTypeFromBytes,
81
+ });
82
+ export const CellDep = struct({
83
+ outPoint: OutPoint,
84
+ depType: DepType,
85
+ }).map({ outMap: ckb.CellDep.from });
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,
95
+ }).map({ outMap: ckb.Transaction.from });
@@ -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,5 +1,3 @@
1
- import { ripemd160 } from "@noble/hashes/ripemd160";
2
- import { sha256 } from "@noble/hashes/sha256";
3
1
  import { Address } from "../../address/index.js";
4
2
  import { bytesConcat, bytesFrom } from "../../bytes/index.js";
5
3
  import { Transaction, WitnessArgs } from "../../ckb/index.js";
@@ -7,6 +5,7 @@ import { KnownScript } from "../../client/index.js";
7
5
  import { hexFrom } from "../../hex/index.js";
8
6
  import { numToBytes } from "../../num/index.js";
9
7
  import { Signer, SignerSignType, SignerType } from "../signer/index.js";
8
+ import { btcEcdsaPublicKeyHash } from "./verify.js";
10
9
  /**
11
10
  * An abstract class extending the Signer class for Bitcoin-like signing operations.
12
11
  * This class provides methods to get Bitcoin account, public key, and internal address,
@@ -43,7 +42,7 @@ export class SignerBtc extends Signer {
43
42
  */
44
43
  async getAddressObjs() {
45
44
  const publicKey = await this.getBtcPublicKey();
46
- const hash = ripemd160(sha256(bytesFrom(publicKey)));
45
+ const hash = btcEcdsaPublicKeyHash(publicKey);
47
46
  return [
48
47
  await Address.fromKnownScript(this.client, KnownScript.OmniLock, hexFrom([0x04, ...hash, 0x00])),
49
48
  ];
@@ -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,7 +1,28 @@
1
1
  import { secp256k1 } from "@noble/curves/secp256k1";
2
+ import { ripemd160 } from "@noble/hashes/ripemd160";
3
+ import { sha256 } from "@noble/hashes/sha256";
2
4
  import { magicHash } from "bitcoinjs-message";
3
- import { bytesFrom } from "../../bytes/index.js";
5
+ import bs58check from "bs58check";
6
+ import { bytesConcat, bytesFrom } from "../../bytes/index.js";
4
7
  import { hexFrom } from "../../hex/index.js";
8
+ /**
9
+ * @public
10
+ */
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
+ }
5
26
  /**
6
27
  * @public
7
28
  */
@@ -0,0 +1,5 @@
1
+ export * from "./signerDoge.js";
2
+ export * from "./signerDogeAddressReadonly.js";
3
+ export * from "./signerDogePrivateKey.js";
4
+ export * from "./verify.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/doge/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./signerDoge.js";
2
+ export * from "./signerDogeAddressReadonly.js";
3
+ export * from "./signerDogePrivateKey.js";
4
+ export * from "./verify.js";
@@ -0,0 +1,52 @@
1
+ import { Address } from "../../address/index.js";
2
+ import { Transaction, TransactionLike } from "../../ckb/index.js";
3
+ import { Signer, SignerSignType, SignerType } from "../signer/index.js";
4
+ /**
5
+ * An abstract class extending the Signer class for Dogecoin-like signing operations.
6
+ * This class provides methods to get Doge account, public key, and internal address,
7
+ * as well as signing transactions.
8
+ * @public
9
+ */
10
+ export declare abstract class SignerDoge extends Signer {
11
+ get type(): SignerType;
12
+ get signType(): SignerSignType;
13
+ /**
14
+ * Gets the Doge address associated with the signer.
15
+ *
16
+ * @returns A promise that resolves to a string representing the Doge account.
17
+ */
18
+ abstract getDogeAddress(): Promise<string>;
19
+ /**
20
+ * Gets the internal address, which is the Doge account in this case.
21
+ *
22
+ * @returns A promise that resolves to a string representing the internal address.
23
+ */
24
+ getInternalAddress(): Promise<string>;
25
+ /**
26
+ * Gets the identity, which is the Doge address in this case.
27
+ *
28
+ * @returns A promise that resolves to a string representing the identity
29
+ */
30
+ getIdentity(): Promise<string>;
31
+ /**
32
+ * Gets an array of Address objects representing the known script addresses for the signer.
33
+ *
34
+ * @returns A promise that resolves to an array of Address objects.
35
+ */
36
+ getAddressObjs(): Promise<Address[]>;
37
+ /**
38
+ * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
39
+ *
40
+ * @param txLike - The transaction to prepare, represented as a TransactionLike object.
41
+ * @returns A promise that resolves to the prepared Transaction object.
42
+ */
43
+ prepareTransaction(txLike: TransactionLike): Promise<Transaction>;
44
+ /**
45
+ * Signs a transaction without modifying it.
46
+ *
47
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
48
+ * @returns A promise that resolves to a signed Transaction object.
49
+ */
50
+ signOnlyTransaction(txLike: TransactionLike): Promise<Transaction>;
51
+ }
52
+ //# sourceMappingURL=signerDoge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signerDoge.d.ts","sourceRoot":"","sources":["../../../src/signer/doge/signerDoge.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,oBAAoB,CAAC;AAI/E,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAExE;;;;;GAKG;AACH,8BAAsB,UAAW,SAAQ,MAAM;IAC7C,IAAI,IAAI,IAAI,UAAU,CAErB;IAED,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAED;;;;OAIG;IACH,QAAQ,CAAC,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAE1C;;;;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;IAY1C;;;;;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;CA6BzE"}
@@ -0,0 +1,82 @@
1
+ import bs58check from "bs58check";
2
+ import { Address } from "../../address/index.js";
3
+ import { bytesConcat, bytesFrom } from "../../bytes/index.js";
4
+ import { Transaction, WitnessArgs } from "../../ckb/index.js";
5
+ import { KnownScript } from "../../client/index.js";
6
+ import { hexFrom } from "../../hex/index.js";
7
+ import { numToBytes } from "../../num/index.js";
8
+ import { Signer, SignerSignType, SignerType } from "../signer/index.js";
9
+ /**
10
+ * An abstract class extending the Signer class for Dogecoin-like signing operations.
11
+ * This class provides methods to get Doge account, public key, and internal address,
12
+ * as well as signing transactions.
13
+ * @public
14
+ */
15
+ export class SignerDoge extends Signer {
16
+ get type() {
17
+ return SignerType.Doge;
18
+ }
19
+ get signType() {
20
+ return SignerSignType.DogeEcdsa;
21
+ }
22
+ /**
23
+ * Gets the internal address, which is the Doge account in this case.
24
+ *
25
+ * @returns A promise that resolves to a string representing the internal address.
26
+ */
27
+ async getInternalAddress() {
28
+ return this.getDogeAddress();
29
+ }
30
+ /**
31
+ * Gets the identity, which is the Doge address in this case.
32
+ *
33
+ * @returns A promise that resolves to a string representing the identity
34
+ */
35
+ async getIdentity() {
36
+ return this.getDogeAddress();
37
+ }
38
+ /**
39
+ * Gets an array of Address objects representing the known script addresses for the signer.
40
+ *
41
+ * @returns A promise that resolves to an array of Address objects.
42
+ */
43
+ async getAddressObjs() {
44
+ const hash = bs58check.decode(await this.getDogeAddress()).slice(1);
45
+ return [
46
+ await Address.fromKnownScript(this.client, KnownScript.OmniLock, hexFrom([0x05, ...hash, 0x00])),
47
+ ];
48
+ }
49
+ /**
50
+ * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
51
+ *
52
+ * @param txLike - The transaction to prepare, represented as a TransactionLike object.
53
+ * @returns A promise that resolves to the prepared Transaction object.
54
+ */
55
+ async prepareTransaction(txLike) {
56
+ const tx = Transaction.from(txLike);
57
+ const { script } = await this.getRecommendedAddressObj();
58
+ await tx.addCellDepsOfKnownScripts(this.client, KnownScript.OmniLock);
59
+ await tx.prepareSighashAllWitness(script, 85, this.client);
60
+ return tx;
61
+ }
62
+ /**
63
+ * Signs a transaction without modifying it.
64
+ *
65
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
66
+ * @returns A promise that resolves to a signed Transaction object.
67
+ */
68
+ async signOnlyTransaction(txLike) {
69
+ const tx = Transaction.from(txLike);
70
+ const { script } = await this.getRecommendedAddressObj();
71
+ const info = await tx.getSignHashInfo(script, this.client);
72
+ if (!info) {
73
+ return tx;
74
+ }
75
+ const signature = bytesFrom(await this.signMessageRaw(info.message.slice(2)), "base64");
76
+ signature[0] = 31 + ((signature[0] - 27) % 4);
77
+ const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
78
+ 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));
79
+ tx.setWitnessArgsAt(info.position, witness);
80
+ return tx;
81
+ }
82
+ }
@@ -0,0 +1,41 @@
1
+ import { Client } from "../../client/index.js";
2
+ import { SignerDoge } from "./signerDoge.js";
3
+ /**
4
+ * A class extending SignerDoge that provides read-only access to a Doge address.
5
+ * This class does not support signing operations.
6
+ * @public
7
+ */
8
+ export declare class SignerDogeAddressReadonly extends SignerDoge {
9
+ private readonly address;
10
+ /**
11
+ * Creates an instance of SignerDogeAddressReadonly.
12
+ *
13
+ * @param client - The client instance used for communication.
14
+ * @param address - The Doge address with the signer.
15
+ */
16
+ constructor(client: Client, address: string);
17
+ /**
18
+ * Connects to the client. This implementation does nothing as the class is read-only.
19
+ *
20
+ * @returns A promise that resolves when the connection is complete.
21
+ */
22
+ connect(): Promise<void>;
23
+ /**
24
+ * Check if the signer is connected.
25
+ *
26
+ * @returns A promise that resolves the connection status.
27
+ */
28
+ isConnected(): Promise<boolean>;
29
+ /**
30
+ * Gets the Doge address associated with the signer.
31
+ *
32
+ * @returns A promise that resolves to a string representing the Doge address.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const account = await signer.getDogeAddress(); // Outputs the Doge address
37
+ * ```
38
+ */
39
+ getDogeAddress(): Promise<string>;
40
+ }
41
+ //# sourceMappingURL=signerDogeAddressReadonly.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signerDogeAddressReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/doge/signerDogeAddressReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;GAIG;AACH,qBAAa,yBAA0B,SAAQ,UAAU;IASrD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAR1B;;;;;OAKG;gBAED,MAAM,EAAE,MAAM,EACG,OAAO,EAAE,MAAM;IAKlC;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;;;;OASG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;CAGxC"}
@@ -0,0 +1,45 @@
1
+ import { SignerDoge } from "./signerDoge.js";
2
+ /**
3
+ * A class extending SignerDoge that provides read-only access to a Doge address.
4
+ * This class does not support signing operations.
5
+ * @public
6
+ */
7
+ export class SignerDogeAddressReadonly extends SignerDoge {
8
+ /**
9
+ * Creates an instance of SignerDogeAddressReadonly.
10
+ *
11
+ * @param client - The client instance used for communication.
12
+ * @param address - The Doge address with the signer.
13
+ */
14
+ constructor(client, address) {
15
+ super(client);
16
+ this.address = address;
17
+ }
18
+ /**
19
+ * Connects to the client. This implementation does nothing as the class is read-only.
20
+ *
21
+ * @returns A promise that resolves when the connection is complete.
22
+ */
23
+ async connect() { }
24
+ /**
25
+ * Check if the signer is connected.
26
+ *
27
+ * @returns A promise that resolves the connection status.
28
+ */
29
+ async isConnected() {
30
+ return true;
31
+ }
32
+ /**
33
+ * Gets the Doge address associated with the signer.
34
+ *
35
+ * @returns A promise that resolves to a string representing the Doge address.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const account = await signer.getDogeAddress(); // Outputs the Doge address
40
+ * ```
41
+ */
42
+ async getDogeAddress() {
43
+ return this.address;
44
+ }
45
+ }
@@ -0,0 +1,52 @@
1
+ import { BytesLike } from "../../bytes/index.js";
2
+ import { Client } from "../../client/index.js";
3
+ import { Hex } from "../../hex/index.js";
4
+ import { SignerDoge } from "./signerDoge.js";
5
+ /**
6
+ * A class extending SignerDoge that provides access to a Doge address.
7
+ * @public
8
+ */
9
+ export declare class SignerDogePrivateKey extends SignerDoge {
10
+ readonly dogeNetwork: number;
11
+ private readonly privateKey;
12
+ /**
13
+ * Creates an instance of SignerDogePrivateKey
14
+ *
15
+ * @param client - The client instance used for communication.
16
+ * @param privateKey - The Doge private key with the signer.
17
+ */
18
+ constructor(client: Client, privateKey: BytesLike, dogeNetwork?: number);
19
+ /**
20
+ * Connects to the client. This implementation does nothing as the class is always connected.
21
+ *
22
+ * @returns A promise that resolves when the connection is complete.
23
+ */
24
+ connect(): Promise<void>;
25
+ /**
26
+ * Check if the signer is connected.
27
+ *
28
+ * @returns A promise that resolves the connection status.
29
+ */
30
+ isConnected(): Promise<boolean>;
31
+ getDogePublicKey(): Promise<Hex>;
32
+ /**
33
+ * Gets the Doge address associated with the signer.
34
+ *
35
+ * @returns A promise that resolves to a string representing the Doge address.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const account = await signer.getDogeAddress(); // Outputs the Doge address
40
+ * ```
41
+ */
42
+ getDogeAddress(): Promise<string>;
43
+ /**
44
+ * Signs a message and returns signature only.
45
+ *
46
+ * @param msg - The message to sign, as a string or BytesLike object.
47
+ * @returns A promise that resolves to the signature as a string.
48
+ * @throws Will throw an error if not implemented.
49
+ */
50
+ signMessageRaw(msg: string | BytesLike): Promise<string>;
51
+ }
52
+ //# sourceMappingURL=signerDogePrivateKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signerDogePrivateKey.d.ts","sourceRoot":"","sources":["../../../src/signer/doge/signerDogePrivateKey.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,SAAS,EAEV,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAW,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,UAAU;aAYhC,WAAW;IAX7B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IAEnC;;;;;OAKG;gBAED,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,SAAS,EACL,WAAW,SAAO;IASpC;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC;IAItC;;;;;;;;;OASG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAOvC;;;;;;OAMG;IACG,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAa/D"}
@@ -0,0 +1,68 @@
1
+ import { secp256k1 } from "@noble/curves/secp256k1";
2
+ import { magicHash } from "bitcoinjs-message";
3
+ import { bytesConcat, bytesFrom, bytesTo, } from "../../bytes/index.js";
4
+ import { hexFrom } from "../../hex/index.js";
5
+ import { btcP2pkhAddressFromPublicKey } from "../btc/verify.js";
6
+ import { SignerDoge } from "./signerDoge.js";
7
+ /**
8
+ * A class extending SignerDoge that provides access to a Doge address.
9
+ * @public
10
+ */
11
+ export class SignerDogePrivateKey extends SignerDoge {
12
+ /**
13
+ * Creates an instance of SignerDogePrivateKey
14
+ *
15
+ * @param client - The client instance used for communication.
16
+ * @param privateKey - The Doge private key with the signer.
17
+ */
18
+ constructor(client, privateKey, dogeNetwork = 0x1e) {
19
+ super(client);
20
+ this.dogeNetwork = dogeNetwork;
21
+ this.privateKey = bytesFrom(privateKey);
22
+ if (this.privateKey.length !== 32) {
23
+ throw new Error("Private key must be 32 bytes!");
24
+ }
25
+ }
26
+ /**
27
+ * Connects to the client. This implementation does nothing as the class is always connected.
28
+ *
29
+ * @returns A promise that resolves when the connection is complete.
30
+ */
31
+ async connect() { }
32
+ /**
33
+ * Check if the signer is connected.
34
+ *
35
+ * @returns A promise that resolves the connection status.
36
+ */
37
+ async isConnected() {
38
+ return true;
39
+ }
40
+ async getDogePublicKey() {
41
+ return hexFrom(secp256k1.getPublicKey(this.privateKey, true));
42
+ }
43
+ /**
44
+ * Gets the Doge address associated with the signer.
45
+ *
46
+ * @returns A promise that resolves to a string representing the Doge address.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const account = await signer.getDogeAddress(); // Outputs the Doge address
51
+ * ```
52
+ */
53
+ async getDogeAddress() {
54
+ return btcP2pkhAddressFromPublicKey(await this.getDogePublicKey(), this.dogeNetwork);
55
+ }
56
+ /**
57
+ * Signs a message and returns signature only.
58
+ *
59
+ * @param msg - The message to sign, as a string or BytesLike object.
60
+ * @returns A promise that resolves to the signature as a string.
61
+ * @throws Will throw an error if not implemented.
62
+ */
63
+ async signMessageRaw(msg) {
64
+ const challenge = typeof msg === "string" ? msg : hexFrom(msg).slice(2);
65
+ const signature = secp256k1.sign(magicHash(challenge, "\x19Dogecoin Signed Message:\n"), this.privateKey);
66
+ return bytesTo(bytesConcat([31 + signature.recovery], signature.toCompactRawBytes()), "base64");
67
+ }
68
+ }
@@ -0,0 +1,6 @@
1
+ import { BytesLike } from "../../bytes/index.js";
2
+ /**
3
+ * @public
4
+ */
5
+ export declare function verifyMessageDogeEcdsa(message: string | BytesLike, signature: string, address: string): boolean;
6
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/signer/doge/verify.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAO5D;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAqBT"}
@@ -0,0 +1,17 @@
1
+ import { secp256k1 } from "@noble/curves/secp256k1";
2
+ import { magicHash } from "bitcoinjs-message";
3
+ import { bytesFrom } from "../../bytes/index.js";
4
+ import { hexFrom } from "../../hex/index.js";
5
+ import { btcEcdsaPublicKeyHash, btcPublicKeyFromP2pkhAddress, } from "../btc/verify.js";
6
+ /**
7
+ * @public
8
+ */
9
+ export function verifyMessageDogeEcdsa(message, signature, address) {
10
+ const challenge = typeof message === "string" ? message : hexFrom(message).slice(2);
11
+ const [recoveryBit, ...rawSign] = bytesFrom(signature, "base64");
12
+ const sig = secp256k1.Signature.fromCompact(hexFrom(rawSign).slice(2)).addRecoveryBit(recoveryBit - 31);
13
+ return (btcPublicKeyFromP2pkhAddress(address) ===
14
+ hexFrom(btcEcdsaPublicKeyHash(sig
15
+ .recoverPublicKey(magicHash(challenge, "\x19Dogecoin Signed Message:\n"))
16
+ .toHex())));
17
+ }