@ckb-ccc/core 0.0.2-alpha.0 → 0.0.2-alpha.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 (208) hide show
  1. package/dist/address/address.advanced.d.ts +5 -0
  2. package/dist/address/address.advanced.d.ts.map +1 -0
  3. package/dist/address/address.advanced.js +68 -0
  4. package/dist/address/advanced.d.ts +7 -9
  5. package/dist/address/advanced.d.ts.map +1 -1
  6. package/dist/address/advanced.js +50 -38
  7. package/dist/address/index.d.ts +20 -5
  8. package/dist/address/index.d.ts.map +1 -1
  9. package/dist/address/index.js +43 -32
  10. package/dist/advanced.d.ts +3 -0
  11. package/dist/advanced.d.ts.map +1 -0
  12. package/dist/{types/index.js → advanced.js} +3 -9
  13. package/dist/advancedBarrel.d.ts +4 -0
  14. package/dist/advancedBarrel.d.ts.map +1 -0
  15. package/dist/advancedBarrel.js +19 -0
  16. package/dist/barrel.d.ts +3 -2
  17. package/dist/barrel.d.ts.map +1 -1
  18. package/dist/barrel.js +3 -2
  19. package/dist/bytes.d.ts +15 -0
  20. package/dist/bytes.d.ts.map +1 -0
  21. package/dist/bytes.js +114 -0
  22. package/dist/ckb/advanced.d.ts +3 -0
  23. package/dist/ckb/advanced.d.ts.map +1 -0
  24. package/dist/ckb/advanced.js +18 -0
  25. package/dist/ckb/hasher.advanced.d.ts +2 -0
  26. package/dist/ckb/hasher.advanced.d.ts.map +1 -0
  27. package/dist/ckb/hasher.advanced.js +4 -0
  28. package/dist/ckb/hasher.d.ts +10 -0
  29. package/dist/ckb/hasher.d.ts.map +1 -0
  30. package/dist/ckb/hasher.js +26 -0
  31. package/dist/ckb/index.d.ts +3 -1
  32. package/dist/ckb/index.d.ts.map +1 -1
  33. package/dist/ckb/index.js +3 -1
  34. package/dist/ckb/types/advanced.d.ts +4 -0
  35. package/dist/ckb/types/advanced.d.ts.map +1 -0
  36. package/dist/ckb/types/advanced.js +32 -0
  37. package/dist/ckb/types/index.d.ts +3 -0
  38. package/dist/ckb/types/index.d.ts.map +1 -0
  39. package/dist/{codec → ckb/types}/index.js +1 -2
  40. package/dist/ckb/types/molecule.advanced/generated.d.ts +355 -0
  41. package/dist/ckb/types/molecule.advanced/generated.d.ts.map +1 -0
  42. package/dist/ckb/types/molecule.advanced/generated.js +1255 -0
  43. package/dist/ckb/types/molecule.advanced/index.d.ts +2 -0
  44. package/dist/ckb/types/molecule.advanced/index.d.ts.map +1 -0
  45. package/dist/ckb/types/molecule.advanced/index.js +17 -0
  46. package/dist/ckb/types/script.advanced.d.ts +4 -0
  47. package/dist/ckb/types/script.advanced.d.ts.map +1 -0
  48. package/dist/{types/ckb.advanced.js → ckb/types/script.advanced.js} +3 -3
  49. package/dist/ckb/types/script.d.ts +26 -0
  50. package/dist/ckb/types/script.d.ts.map +1 -0
  51. package/dist/ckb/types/script.js +75 -0
  52. package/dist/ckb/types/transaction.advanced.d.ts +4 -0
  53. package/dist/ckb/types/transaction.advanced.d.ts.map +1 -0
  54. package/dist/ckb/types/transaction.advanced.js +11 -0
  55. package/dist/ckb/types/transaction.d.ts +127 -0
  56. package/dist/ckb/types/transaction.d.ts.map +1 -0
  57. package/dist/ckb/types/transaction.js +266 -0
  58. package/dist/ckb/viewerCkbScript.d.ts +11 -0
  59. package/dist/ckb/viewerCkbScript.d.ts.map +1 -0
  60. package/dist/ckb/viewerCkbScript.js +18 -0
  61. package/dist/client/advanced.d.ts +3 -0
  62. package/dist/client/advanced.d.ts.map +1 -0
  63. package/dist/client/advanced.js +18 -0
  64. package/dist/client/client.d.ts +7 -4
  65. package/dist/client/client.d.ts.map +1 -1
  66. package/dist/client/client.js +1 -4
  67. package/dist/client/clientPublicMainnet.advanced.d.ts +1 -1
  68. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  69. package/dist/client/clientPublicMainnet.d.ts +5 -3
  70. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  71. package/dist/client/clientPublicMainnet.js +6 -3
  72. package/dist/client/clientPublicTestnet.advanced.d.ts +1 -1
  73. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  74. package/dist/client/clientPublicTestnet.d.ts +5 -3
  75. package/dist/client/clientPublicTestnet.d.ts.map +1 -1
  76. package/dist/client/clientPublicTestnet.js +6 -3
  77. package/dist/client/clientTypes.d.ts +2 -0
  78. package/dist/client/clientTypes.d.ts.map +1 -0
  79. package/dist/client/index.d.ts +1 -4
  80. package/dist/client/index.d.ts.map +1 -1
  81. package/dist/client/index.js +1 -19
  82. package/dist/client/jsonRpc/advanced.d.ts +88 -0
  83. package/dist/client/jsonRpc/advanced.d.ts.map +1 -0
  84. package/dist/client/jsonRpc/advanced.js +69 -0
  85. package/dist/client/jsonRpc/index.d.ts +14 -0
  86. package/dist/client/jsonRpc/index.d.ts.map +1 -0
  87. package/dist/client/jsonRpc/index.js +63 -0
  88. package/dist/fixedPoint.d.ts +9 -0
  89. package/dist/fixedPoint.d.ts.map +1 -0
  90. package/dist/fixedPoint.js +30 -0
  91. package/dist/primitive.d.ts +5 -0
  92. package/dist/primitive.d.ts.map +1 -0
  93. package/dist/signer/helpers.d.ts +7 -0
  94. package/dist/signer/helpers.d.ts.map +1 -0
  95. package/dist/signer/helpers.js +35 -0
  96. package/dist/signer/index.d.ts +3 -0
  97. package/dist/signer/index.d.ts.map +1 -0
  98. package/dist/signer/index.js +18 -0
  99. package/dist/signer/signer.d.ts +11 -0
  100. package/dist/signer/signer.d.ts.map +1 -0
  101. package/dist/signer/signer.js +13 -0
  102. package/dist/tsconfig.tsbuildinfo +1 -1
  103. package/dist/viewer.d.ts +8 -5
  104. package/dist/viewer.d.ts.map +1 -1
  105. package/dist/viewer.js +13 -0
  106. package/package.json +13 -5
  107. package/src/address/address.advanced.ts +88 -0
  108. package/src/address/advanced.ts +30 -45
  109. package/src/address/index.ts +70 -5
  110. package/src/advanced.ts +2 -0
  111. package/src/advancedBarrel.ts +3 -0
  112. package/src/barrel.ts +3 -2
  113. package/src/bytes.ts +127 -0
  114. package/src/ckb/advanced.ts +2 -0
  115. package/src/ckb/hasher.advanced.ts +1 -0
  116. package/src/ckb/hasher.ts +30 -0
  117. package/src/ckb/index.ts +3 -1
  118. package/src/ckb/types/advanced.ts +3 -0
  119. package/src/ckb/types/index.ts +2 -0
  120. package/src/ckb/types/molecule.advanced/blockchain.mol +118 -0
  121. package/src/ckb/types/molecule.advanced/generated.d.ts +433 -0
  122. package/src/ckb/types/molecule.advanced/generated.js +1376 -0
  123. package/src/ckb/types/molecule.advanced/index.ts +1 -0
  124. package/src/ckb/types/script.advanced.ts +14 -0
  125. package/src/ckb/types/script.ts +70 -0
  126. package/src/ckb/types/transaction.advanced.ts +10 -0
  127. package/src/ckb/types/transaction.ts +366 -0
  128. package/src/ckb/viewerCkbScript.ts +21 -0
  129. package/src/client/advanced.ts +2 -0
  130. package/src/client/client.ts +11 -4
  131. package/src/client/clientPublicMainnet.advanced.ts +1 -1
  132. package/src/client/clientPublicMainnet.ts +9 -4
  133. package/src/client/clientPublicTestnet.advanced.ts +1 -1
  134. package/src/client/clientPublicTestnet.ts +9 -4
  135. package/src/client/clientTypes.ts +1 -0
  136. package/src/client/index.ts +1 -7
  137. package/src/client/jsonRpc/advanced.ts +93 -0
  138. package/src/client/jsonRpc/index.ts +83 -0
  139. package/src/fixedPoint.ts +53 -0
  140. package/src/primitive.ts +8 -0
  141. package/src/signer/helpers.ts +43 -0
  142. package/src/signer/index.ts +2 -0
  143. package/src/signer/signer.ts +19 -0
  144. package/src/viewer.ts +16 -8
  145. package/dist/address/address.d.ts +0 -8
  146. package/dist/address/address.d.ts.map +0 -1
  147. package/dist/address/address.js +0 -6
  148. package/dist/address/addressKnownScript.d.ts +0 -13
  149. package/dist/address/addressKnownScript.d.ts.map +0 -1
  150. package/dist/address/addressKnownScript.js +0 -27
  151. package/dist/address/addressPlain.d.ts +0 -12
  152. package/dist/address/addressPlain.d.ts.map +0 -1
  153. package/dist/address/addressPlain.js +0 -23
  154. package/dist/address/converter.d.ts +0 -8
  155. package/dist/address/converter.d.ts.map +0 -1
  156. package/dist/address/converter.js +0 -65
  157. package/dist/bundle.d.ts +0 -9
  158. package/dist/bundle.d.ts.map +0 -1
  159. package/dist/bundle.js +0 -25
  160. package/dist/ckb/viewerCkbAddress.d.ts +0 -14
  161. package/dist/ckb/viewerCkbAddress.d.ts.map +0 -1
  162. package/dist/ckb/viewerCkbAddress.js +0 -28
  163. package/dist/codec/bytes.d.ts +0 -4
  164. package/dist/codec/bytes.d.ts.map +0 -1
  165. package/dist/codec/bytes.js +0 -29
  166. package/dist/codec/hashType.d.ts +0 -4
  167. package/dist/codec/hashType.d.ts.map +0 -1
  168. package/dist/codec/hashType.js +0 -13
  169. package/dist/codec/index.d.ts +0 -4
  170. package/dist/codec/index.d.ts.map +0 -1
  171. package/dist/codec/script.d.ts +0 -4
  172. package/dist/codec/script.d.ts.map +0 -1
  173. package/dist/codec/script.js +0 -22
  174. package/dist/signer.d.ts +0 -9
  175. package/dist/signer.d.ts.map +0 -1
  176. package/dist/signer.js +0 -12
  177. package/dist/types/cell.d.ts +0 -5
  178. package/dist/types/cell.d.ts.map +0 -1
  179. package/dist/types/cell.js +0 -8
  180. package/dist/types/ckb.advanced.d.ts +0 -4
  181. package/dist/types/ckb.advanced.d.ts.map +0 -1
  182. package/dist/types/ckb.d.ts +0 -16
  183. package/dist/types/ckb.d.ts.map +0 -1
  184. package/dist/types/ckb.js +0 -36
  185. package/dist/types/index.d.ts +0 -9
  186. package/dist/types/index.d.ts.map +0 -1
  187. package/dist/types/lumos.d.ts +0 -90
  188. package/dist/types/lumos.d.ts.map +0 -1
  189. package/dist/types/primitive.d.ts +0 -3
  190. package/dist/types/primitive.d.ts.map +0 -1
  191. package/src/address/address.ts +0 -9
  192. package/src/address/addressKnownScript.ts +0 -31
  193. package/src/address/addressPlain.ts +0 -27
  194. package/src/address/converter.ts +0 -93
  195. package/src/ckb/viewerCkbAddress.ts +0 -34
  196. package/src/codec/bytes.ts +0 -30
  197. package/src/codec/hashType.ts +0 -10
  198. package/src/codec/index.ts +0 -3
  199. package/src/codec/script.ts +0 -21
  200. package/src/signer.ts +0 -20
  201. package/src/types/cell.ts +0 -5
  202. package/src/types/ckb.advanced.ts +0 -14
  203. package/src/types/ckb.ts +0 -47
  204. package/src/types/index.ts +0 -9
  205. package/src/types/lumos.ts +0 -101
  206. package/src/types/primitive.ts +0 -2
  207. /package/dist/{types/lumos.js → client/clientTypes.js} +0 -0
  208. /package/dist/{types/primitive.js → primitive.js} +0 -0
package/dist/signer.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Signer = void 0;
4
- const viewer_1 = require("./viewer");
5
- class Signer extends viewer_1.Viewer {
6
- // Will be deprecated in the future
7
- signLumosTransaction(tx) {
8
- const completedTx = this.completeLumosTransaction(tx);
9
- return this.signOnlyLumosTransaction(tx);
10
- }
11
- }
12
- exports.Signer = Signer;
@@ -1,5 +0,0 @@
1
- export declare class Cell {
2
- constructor();
3
- static from(): void;
4
- }
5
- //# sourceMappingURL=cell.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cell.d.ts","sourceRoot":"","sources":["../../src/types/cell.ts"],"names":[],"mappings":"AAAA,qBAAa,IAAI;;IAGf,MAAM,CAAC,IAAI;CACZ"}
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Cell = void 0;
4
- class Cell {
5
- constructor() { }
6
- static from() { }
7
- }
8
- exports.Cell = Cell;
@@ -1,4 +0,0 @@
1
- import { HashType } from "./ckb";
2
- export declare const HASHTYPE_TO_NUM: Record<HashType, number>;
3
- export declare const NUM_TO_HASHTYPE: Record<number, HashType>;
4
- //# sourceMappingURL=ckb.advanced.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ckb.advanced.d.ts","sourceRoot":"","sources":["../../src/types/ckb.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAKpD,CAAC;AACF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAKpD,CAAC"}
@@ -1,16 +0,0 @@
1
- import { BytesLike, HexString } from "./primitive";
2
- export type HashType = "type" | "data" | "data1" | "data2";
3
- export declare function parseHashType(hashType: HashType): number;
4
- export declare function formatHashType(hashType: number): HashType;
5
- export declare class Script {
6
- readonly codeHash: HexString;
7
- readonly hashType: HashType;
8
- readonly args: HexString;
9
- constructor(codeHash: HexString, hashType: HashType, args: HexString);
10
- static from({ codeHash, hashType, args, }: {
11
- codeHash: BytesLike;
12
- hashType: string;
13
- args: BytesLike;
14
- }): Script;
15
- }
16
- //# sourceMappingURL=ckb.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ckb.d.ts","sourceRoot":"","sources":["../../src/types/ckb.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAC3D,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,UAQ/C;AACD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAQzD;AAED,qBAAa,MAAM;aAEC,QAAQ,EAAE,SAAS;aACnB,QAAQ,EAAE,QAAQ;aAClB,IAAI,EAAE,SAAS;gBAFf,QAAQ,EAAE,SAAS,EACnB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,SAAS;IAGjC,MAAM,CAAC,IAAI,CAAC,EACV,QAAQ,EACR,QAAQ,EACR,IAAI,GACL,EAAE;QACD,QAAQ,EAAE,SAAS,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,SAAS,CAAC;KACjB,GAAG,MAAM;CAOX"}
package/dist/types/ckb.js DELETED
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Script = exports.formatHashType = exports.parseHashType = void 0;
4
- const codec_1 = require("../codec");
5
- const ckb_advanced_1 = require("./ckb.advanced");
6
- function parseHashType(hashType) {
7
- const val = ckb_advanced_1.HASHTYPE_TO_NUM[hashType];
8
- if (val === undefined) {
9
- throw new Error(`Invalid hash type ${hashType}`);
10
- }
11
- return val;
12
- }
13
- exports.parseHashType = parseHashType;
14
- function formatHashType(hashType) {
15
- const val = ckb_advanced_1.NUM_TO_HASHTYPE[hashType];
16
- if (val === undefined) {
17
- throw new Error(`Invalid hash type ${hashType}`);
18
- }
19
- return val;
20
- }
21
- exports.formatHashType = formatHashType;
22
- class Script {
23
- constructor(codeHash, hashType, args) {
24
- this.codeHash = codeHash;
25
- this.hashType = hashType;
26
- this.args = args;
27
- }
28
- static from({ codeHash, hashType, args, }) {
29
- return {
30
- codeHash: (0, codec_1.toHex)(codeHash),
31
- hashType: hashType,
32
- args: (0, codec_1.toHex)(args),
33
- };
34
- }
35
- }
36
- exports.Script = Script;
@@ -1,9 +0,0 @@
1
- export * from "./cell";
2
- export * from "./ckb";
3
- export * as lumos from "./lumos";
4
- export * from "./primitive";
5
- export declare const AdvancedType: {
6
- HASHTYPE_TO_NUM: Record<import("./ckb").HashType, number>;
7
- NUM_TO_HASHTYPE: Record<number, import("./ckb").HashType>;
8
- };
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AAEvB,cAAc,OAAO,CAAC;AACtB,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,cAAc,aAAa,CAAC;AAE5B,eAAO,MAAM,YAAY;;;CAExB,CAAA"}
@@ -1,90 +0,0 @@
1
- import { List, Map as ImmutableMap, Record } from "immutable";
2
- export type HexString = string;
3
- export type Hexadecimal = string;
4
- export type Hash = HexString;
5
- export type HexNumber = Hexadecimal;
6
- export type PackedSince = string;
7
- export type PackedDao = string;
8
- export type Address = string;
9
- export type HexadecimalRange = [Hexadecimal, Hexadecimal];
10
- export type HashType = "type" | "data" | "data1" | "data2";
11
- export interface Script {
12
- codeHash: Hash;
13
- hashType: HashType;
14
- args: HexString;
15
- }
16
- export interface OutPoint {
17
- txHash: Hash;
18
- index: HexNumber;
19
- }
20
- export type DepType = "depGroup" | "code";
21
- export interface CellDep {
22
- outPoint: OutPoint;
23
- depType: DepType;
24
- }
25
- export interface Cell {
26
- cellOutput: {
27
- capacity: HexNumber;
28
- lock: Script;
29
- type?: Script;
30
- };
31
- data: HexString;
32
- outPoint?: OutPoint;
33
- blockHash?: Hash;
34
- blockNumber?: HexNumber;
35
- txIndex?: HexNumber;
36
- }
37
- export type SearchMode = "exact" | "prefix";
38
- export type DataWithSearchMode = {
39
- searchMode: SearchMode;
40
- data: HexString;
41
- };
42
- export interface ScriptWrapper {
43
- script: Script;
44
- searchMode?: SearchMode;
45
- ioType?: "input" | "output" | "both";
46
- argsLen?: number | "any";
47
- }
48
- export interface QueryOptions {
49
- lock?: Script | ScriptWrapper;
50
- type?: Script | ScriptWrapper | "empty";
51
- data?: string | "any" | DataWithSearchMode;
52
- /** `lock` script args length */
53
- argsLen?: number | "any";
54
- /** `fromBlock` itself is included in range query. */
55
- fromBlock?: Hexadecimal;
56
- /** `toBlock` itself is included in range query. */
57
- toBlock?: Hexadecimal;
58
- skip?: number;
59
- order?: "asc" | "desc";
60
- }
61
- export interface CellCollectorResults {
62
- [Symbol.asyncIterator](): AsyncIterator<Cell>;
63
- }
64
- export interface CellCollector {
65
- collect(): CellCollectorResults;
66
- }
67
- export interface CellProvider {
68
- uri?: string;
69
- collector(queryOptions: QueryOptions): CellCollector;
70
- }
71
- export interface TransactionSkeletonInterface {
72
- cellProvider: CellProvider | null;
73
- cellDeps: List<CellDep>;
74
- headerDeps: List<Hash>;
75
- inputs: List<Cell>;
76
- outputs: List<Cell>;
77
- witnesses: List<HexString>;
78
- fixedEntries: List<{
79
- field: string;
80
- index: number;
81
- }>;
82
- signingEntries: List<{
83
- type: string;
84
- index: number;
85
- message: string;
86
- }>;
87
- inputSinces: ImmutableMap<number, PackedSince>;
88
- }
89
- export type TransactionSkeletonType = Record<TransactionSkeletonInterface> & Readonly<TransactionSkeletonInterface>;
90
- //# sourceMappingURL=lumos.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lumos.d.ts","sourceRoot":"","sources":["../../src/types/lumos.ts"],"names":[],"mappings":"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"}
@@ -1,3 +0,0 @@
1
- export type HexString = `0x${string}`;
2
- export type BytesLike = HexString | Uint8Array | number[];
3
- //# sourceMappingURL=primitive.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"primitive.d.ts","sourceRoot":"","sources":["../../src/types/primitive.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,KAAK,MAAM,EAAE,CAAC;AACtC,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,MAAM,EAAE,CAAC"}
@@ -1,9 +0,0 @@
1
- import { Client } from "../client";
2
- import { Script } from "../types";
3
-
4
- export abstract class Address {
5
- abstract getClient(): Promise<Client>;
6
-
7
- abstract getAddress(): Promise<string>;
8
- abstract getScript(): Promise<Script>;
9
- }
@@ -1,31 +0,0 @@
1
- import { Client, KnownScript } from "../client";
2
- import { Script } from "../types";
3
- import { Address } from "./address";
4
- import { encodeScriptToAddress } from "./converter";
5
-
6
- export class AddressKnownScript extends Address {
7
- constructor(
8
- private readonly script: KnownScript,
9
- private readonly args: Script["args"],
10
- private readonly client: Client,
11
- ) {
12
- super();
13
- }
14
-
15
- async getClient(): Promise<Client> {
16
- return this.client;
17
- }
18
-
19
- async getAddress(): Promise<string> {
20
- const prefix = await (await this.getClient()).getAddressPrefix();
21
-
22
- return encodeScriptToAddress(prefix, await this.getScript());
23
- }
24
-
25
- async getScript(): Promise<Script> {
26
- return {
27
- ...(await this.client.getKnownScript(this.script)),
28
- args: this.args,
29
- };
30
- }
31
- }
@@ -1,27 +0,0 @@
1
- import { Client } from "../client";
2
- import { Script } from "../types";
3
- import { Address } from "./address";
4
- import { encodeScriptToAddress } from "./converter";
5
-
6
- export class AddressPlain extends Address {
7
- constructor(
8
- private readonly script: Script,
9
- private readonly client: Client,
10
- ) {
11
- super();
12
- }
13
-
14
- async getClient(): Promise<Client> {
15
- return this.client;
16
- }
17
-
18
- async getAddress(): Promise<string> {
19
- const prefix = await (await this.getClient()).getAddressPrefix();
20
-
21
- return encodeScriptToAddress(prefix, this.script);
22
- }
23
-
24
- async getScript(): Promise<Script> {
25
- return this.script;
26
- }
27
- }
@@ -1,93 +0,0 @@
1
- import { Client, KnownScript } from "../client";
2
- import { Script } from "../types";
3
- import { toHex, decodeScript, encodeScript } from "../codec";
4
- import { AddressPlain } from "./addressPlain";
5
- import {
6
- AddressFormat,
7
- BECH32_LIMIT,
8
- getClientFromAddressPrefix,
9
- parseAddress,
10
- } from "./advanced";
11
- import { AddressKnownScript } from "./addressKnownScript";
12
- import { Address } from "./address";
13
- import { bech32m } from "bech32";
14
-
15
- export function decodeAddressFromString(
16
- address: string,
17
- getClient?: (prefix: string) => Client | undefined,
18
- ): Address {
19
- const { prefix, format, body } = parseAddress(address);
20
-
21
- const client = getClient?.(prefix) ?? getClientFromAddressPrefix(prefix);
22
- if (!client) {
23
- throw new Error(`Unknown address prefix ${prefix}`);
24
- }
25
-
26
- if (format === AddressFormat.Full) {
27
- if (body.length < 32 + 1) {
28
- throw new Error(`Invalid address without enough payload ${address}`);
29
- }
30
-
31
- return new AddressPlain(decodeScript(body), client);
32
- }
33
-
34
- if (format === AddressFormat.FullData) {
35
- if (body.length < 32) {
36
- throw new Error(`Invalid address without enough payload ${address}`);
37
- }
38
-
39
- return new AddressPlain(
40
- {
41
- codeHash: toHex(body.slice(0, 32)),
42
- hashType: "data",
43
- args: toHex(body.slice(32)),
44
- },
45
- client,
46
- );
47
- }
48
-
49
- if (format === AddressFormat.FullType) {
50
- if (body.length < 32) {
51
- throw new Error(`Invalid address without enough payload ${address}`);
52
- }
53
-
54
- return new AddressPlain(
55
- {
56
- codeHash: toHex(body.slice(0, 32)),
57
- hashType: "type",
58
- args: toHex(body.slice(32)),
59
- },
60
- client,
61
- );
62
- }
63
-
64
- // format === AddressFormat.Short
65
- if (body.length !== 21) {
66
- throw new Error(`Invalid address without enough payload ${address}`);
67
- }
68
- const script = [
69
- KnownScript.Secp256k1Blake160,
70
- KnownScript.Secp256k1Multisig,
71
- KnownScript.AnyoneCanPay,
72
- ][body[0]];
73
- if (script === undefined) {
74
- throw new Error(
75
- `Invalid short format address with unknown script ${address}`,
76
- );
77
- }
78
-
79
- return new AddressKnownScript(script, toHex(body.slice(1)), client);
80
- }
81
-
82
- export function decodeAddressFromScript(
83
- script: Script,
84
- client: Client,
85
- ): AddressPlain {
86
- return new AddressPlain(script, client);
87
- }
88
-
89
- export function encodeScriptToAddress(prefix: string, script: Script) {
90
- const data = [AddressFormat.Full, ...encodeScript(script)];
91
-
92
- return bech32m.encode(prefix, bech32m.toWords(data), BECH32_LIMIT);
93
- }
@@ -1,34 +0,0 @@
1
- import { encodeScriptToAddress } from "../address";
2
- import { Client } from "../client";
3
- import { Script } from "../types";
4
- import { Viewer } from "../viewer";
5
- import { TransactionSkeletonType } from "../types/lumos";
6
-
7
- export class ViewerCkbAddress extends Viewer {
8
- constructor(
9
- private readonly script: Script,
10
- private readonly client: Client,
11
- ) {
12
- super();
13
- }
14
-
15
- async getClient(): Promise<Client> {
16
- return this.client;
17
- }
18
-
19
- async getRecommendedAddress(): Promise<string> {
20
- return (await this.getAddresses())[0];
21
- }
22
- async getAddresses(): Promise<string[]> {
23
- return [
24
- encodeScriptToAddress(await this.client.getAddressPrefix(), this.script),
25
- ];
26
- }
27
-
28
- // Will be deprecated in the future
29
- async completeLumosTransaction(
30
- tx: TransactionSkeletonType,
31
- ): Promise<TransactionSkeletonType> {
32
- return tx;
33
- }
34
- }
@@ -1,30 +0,0 @@
1
- import { BytesLike, HexString } from "../types";
2
- import { Buffer } from "buffer";
3
-
4
- export function toBytes(bytes: BytesLike | string): Uint8Array {
5
- if (bytes instanceof Uint8Array) {
6
- return bytes;
7
- }
8
-
9
- if (Array.isArray(bytes)) {
10
- if (bytes.some((v) => v < 0 || 0xff < v)) {
11
- throw new Error(`Invalid bytes ${bytes}`);
12
- }
13
- return new Uint8Array(bytes);
14
- }
15
-
16
- if (bytes.length % 2 !== 0) {
17
- throw new Error(`Invalid bytes with odd length ${bytes}`);
18
- }
19
-
20
- const strData = bytes.startsWith("0x") ? bytes.slice(2) : bytes;
21
- const data = Buffer.from(strData, "hex");
22
- if (data.length * 2 !== strData.length) {
23
- throw new Error(`Invalid bytes ${bytes}`);
24
- }
25
- return data;
26
- }
27
-
28
- export function toHex(bytes: BytesLike | string): HexString {
29
- return `0x${new Buffer(toBytes(bytes)).toString("hex")}`;
30
- }
@@ -1,10 +0,0 @@
1
- import { BytesLike, HashType, formatHashType, parseHashType } from "../types";
2
- import { toBytes } from "./bytes";
3
-
4
- export function encodeHashType(hashType: HashType): Uint8Array {
5
- return toBytes([parseHashType(hashType)]);
6
- }
7
-
8
- export function decodeHashType(bytes: BytesLike): HashType {
9
- return formatHashType(toBytes(bytes)[0]);
10
- }
@@ -1,3 +0,0 @@
1
- export * from "./bytes";
2
- export * from "./hashType";
3
- export * from "./script";
@@ -1,21 +0,0 @@
1
- import { BytesLike, Script } from "../types";
2
- import { toBytes, toHex } from "./bytes";
3
- import { decodeHashType, encodeHashType } from "./hashType";
4
-
5
- export function encodeScript(script: Script): Uint8Array {
6
- return toBytes([
7
- ...toBytes(script.codeHash),
8
- ...encodeHashType(script.hashType),
9
- ...toBytes(script.args),
10
- ]);
11
- }
12
-
13
- export function decodeScript(bytes: BytesLike): Script {
14
- const formattedBytes = toBytes(bytes);
15
-
16
- return {
17
- codeHash: toHex(formattedBytes.slice(0, 32)),
18
- hashType: decodeHashType(formattedBytes.slice(32, 33)),
19
- args: toHex(formattedBytes.slice(33)),
20
- };
21
- }
package/src/signer.ts DELETED
@@ -1,20 +0,0 @@
1
- import { TransactionSkeletonType } from "./types/lumos";
2
- import { Viewer } from "./viewer";
3
- import { BytesLike, HexString } from "./types";
4
-
5
- export abstract class Signer extends Viewer {
6
- abstract signMessage(message: string | BytesLike): Promise<HexString>;
7
-
8
- // Will be deprecated in the future
9
- signLumosTransaction(
10
- tx: TransactionSkeletonType,
11
- ): Promise<TransactionSkeletonType> {
12
- const completedTx = this.completeLumosTransaction(tx);
13
- return this.signOnlyLumosTransaction(tx);
14
- }
15
-
16
- // Will be deprecated in the future
17
- abstract signOnlyLumosTransaction(
18
- tx: TransactionSkeletonType,
19
- ): Promise<TransactionSkeletonType>;
20
- }
package/src/types/cell.ts DELETED
@@ -1,5 +0,0 @@
1
- export class Cell {
2
- constructor() {}
3
-
4
- static from() {}
5
- }
@@ -1,14 +0,0 @@
1
- import { HashType } from "./ckb";
2
-
3
- export const HASHTYPE_TO_NUM: Record<HashType, number> = {
4
- type: 0x01,
5
- data: 0x00,
6
- data1: 0x02,
7
- data2: 0x04,
8
- };
9
- export const NUM_TO_HASHTYPE: Record<number, HashType> = {
10
- 0x01: "type",
11
- 0x00: "data",
12
- 0x02: "data1",
13
- 0x04: "data2",
14
- };
package/src/types/ckb.ts DELETED
@@ -1,47 +0,0 @@
1
- import { toHex } from "../codec";
2
- import { HASHTYPE_TO_NUM, NUM_TO_HASHTYPE } from "./ckb.advanced";
3
- import { BytesLike, HexString } from "./primitive";
4
-
5
- export type HashType = "type" | "data" | "data1" | "data2";
6
- export function parseHashType(hashType: HashType) {
7
- const val = HASHTYPE_TO_NUM[hashType];
8
-
9
- if (val === undefined) {
10
- throw new Error(`Invalid hash type ${hashType}`);
11
- }
12
-
13
- return val;
14
- }
15
- export function formatHashType(hashType: number): HashType {
16
- const val = NUM_TO_HASHTYPE[hashType];
17
-
18
- if (val === undefined) {
19
- throw new Error(`Invalid hash type ${hashType}`);
20
- }
21
-
22
- return val;
23
- }
24
-
25
- export class Script {
26
- constructor(
27
- public readonly codeHash: HexString,
28
- public readonly hashType: HashType,
29
- public readonly args: HexString,
30
- ) {}
31
-
32
- static from({
33
- codeHash,
34
- hashType,
35
- args,
36
- }: {
37
- codeHash: BytesLike;
38
- hashType: string;
39
- args: BytesLike;
40
- }): Script {
41
- return {
42
- codeHash: toHex(codeHash),
43
- hashType: hashType as HashType,
44
- args: toHex(args),
45
- };
46
- }
47
- }
@@ -1,9 +0,0 @@
1
- export * from "./cell";
2
- import * as ckbAdvanced from "./ckb.advanced";
3
- export * from "./ckb";
4
- export * as lumos from "./lumos";
5
- export * from "./primitive";
6
-
7
- export const AdvancedType = {
8
- ...ckbAdvanced,
9
- }