@ckb-ccc/core 0.0.2-alpha.3 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/address/address.advanced.js +29 -34
  2. package/dist/address/advanced.js +1 -17
  3. package/dist/address/index.js +12 -16
  4. package/dist/advanced.js +2 -31
  5. package/dist/advancedBarrel.js +4 -20
  6. package/dist/barrel.js +10 -26
  7. package/dist/bytes/index.js +8 -15
  8. package/dist/ckb/advanced.js +3 -32
  9. package/dist/ckb/index.js +2 -18
  10. package/dist/ckb/molecule.advanced/generated.js +64 -132
  11. package/dist/ckb/molecule.advanced/index.js +2 -20
  12. package/dist/ckb/script.advanced.js +3 -6
  13. package/dist/ckb/script.js +19 -49
  14. package/dist/ckb/transaction.advanced.js +3 -6
  15. package/dist/ckb/transaction.js +54 -89
  16. package/dist/client/advanced.js +2 -18
  17. package/dist/client/client.d.ts +1 -0
  18. package/dist/client/client.d.ts.map +1 -1
  19. package/dist/client/client.js +2 -5
  20. package/dist/client/clientPublicMainnet.advanced.js +7 -10
  21. package/dist/client/clientPublicMainnet.js +4 -8
  22. package/dist/client/clientPublicTestnet.advanced.js +7 -10
  23. package/dist/client/clientPublicTestnet.js +4 -8
  24. package/dist/client/clientTypes.js +1 -2
  25. package/dist/client/index.js +4 -20
  26. package/dist/client/jsonRpc/advanced.js +13 -17
  27. package/dist/client/jsonRpc/index.js +5 -12
  28. package/dist/fixedPoint/index.js +4 -9
  29. package/dist/hasher/advanced.js +1 -4
  30. package/dist/hasher/index.js +8 -16
  31. package/dist/hex/index.js +4 -8
  32. package/dist/index.js +2 -31
  33. package/dist/num/index.js +15 -26
  34. package/dist/signer/helpers.js +7 -11
  35. package/dist/signer/index.js +4 -20
  36. package/dist/signer/signer.js +1 -5
  37. package/dist/signer/signerReadonly.js +2 -6
  38. package/dist/signer/signerReadonlyCkbScript.js +4 -8
  39. package/dist/utils/index.js +1 -5
  40. package/package.json +2 -2
  41. package/src/client/client.ts +2 -0
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CkbRpcMethods = exports.JsonRpcTransformers = void 0;
4
- const ckb_1 = require("../../ckb");
5
- const hex_1 = require("../../hex");
6
- const num_1 = require("../../num");
7
- const utils_1 = require("../../utils");
8
- class JsonRpcTransformers {
1
+ import { depTypeFrom, } from "../../ckb";
2
+ import { hexFrom } from "../../hex";
3
+ import { numToHex } from "../../num";
4
+ import { apply } from "../../utils";
5
+ export class JsonRpcTransformers {
9
6
  static toDepType(depType) {
10
- switch ((0, ckb_1.depTypeFrom)(depType)) {
7
+ switch (depTypeFrom(depType)) {
11
8
  case "code":
12
9
  return "code";
13
10
  case "depGroup":
@@ -23,21 +20,21 @@ class JsonRpcTransformers {
23
20
  }
24
21
  static toOutPoint(outPoint) {
25
22
  return {
26
- index: (0, num_1.numToHex)(outPoint.index),
23
+ index: numToHex(outPoint.index),
27
24
  tx_hash: outPoint.txHash,
28
25
  };
29
26
  }
30
27
  static toCellInput(cellInput) {
31
28
  return {
32
29
  previous_output: JsonRpcTransformers.toOutPoint(cellInput.previousOutput),
33
- since: (0, num_1.numToHex)(cellInput.since),
30
+ since: numToHex(cellInput.since),
34
31
  };
35
32
  }
36
33
  static toCellOutput(cellOutput) {
37
34
  return {
38
- capacity: (0, num_1.numToHex)(cellOutput.capacity),
35
+ capacity: numToHex(cellOutput.capacity),
39
36
  lock: JsonRpcTransformers.toScript(cellOutput.lock),
40
- type: (0, utils_1.apply)(JsonRpcTransformers.toScript, cellOutput.type),
37
+ type: apply(JsonRpcTransformers.toScript, cellOutput.type),
41
38
  };
42
39
  }
43
40
  static toCellDep(cellDep) {
@@ -48,7 +45,7 @@ class JsonRpcTransformers {
48
45
  }
49
46
  static toTransaction(tx) {
50
47
  return {
51
- version: (0, num_1.numToHex)(tx.version),
48
+ version: numToHex(tx.version),
52
49
  cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.toCellDep(c)),
53
50
  header_deps: tx.headerDeps,
54
51
  inputs: tx.inputs.map((i) => JsonRpcTransformers.toCellInput(i)),
@@ -58,12 +55,11 @@ class JsonRpcTransformers {
58
55
  };
59
56
  }
60
57
  }
61
- exports.JsonRpcTransformers = JsonRpcTransformers;
62
- exports.CkbRpcMethods = [
58
+ export const CkbRpcMethods = [
63
59
  {
64
60
  method: "sendTransaction",
65
61
  rpcMethod: "send_transaction",
66
62
  inTransformers: [JsonRpcTransformers.toTransaction],
67
- outTransformer: hex_1.hexFrom,
63
+ outTransformer: hexFrom,
68
64
  },
69
65
  ];
@@ -1,22 +1,16 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ClientJsonRpc = void 0;
7
- const cross_fetch_1 = __importDefault(require("cross-fetch"));
8
- const advanced_1 = require("./advanced");
1
+ import fetch from "cross-fetch";
2
+ import { CkbRpcMethods } from "./advanced";
9
3
  async function transform(value, transformer) {
10
4
  if (transformer) {
11
5
  return transformer(value);
12
6
  }
13
7
  return value;
14
8
  }
15
- class ClientJsonRpc {
9
+ export class ClientJsonRpc {
16
10
  constructor(url, timeout = 30000) {
17
11
  this.url = url;
18
12
  this.timeout = timeout;
19
- advanced_1.CkbRpcMethods.map((method) => Object.defineProperty(this, method.method, {
13
+ CkbRpcMethods.map((method) => Object.defineProperty(this, method.method, {
20
14
  value: this.buildSender(method),
21
15
  enumerable: true,
22
16
  }));
@@ -33,7 +27,7 @@ class ClientJsonRpc {
33
27
  async send(payload) {
34
28
  const aborter = new AbortController();
35
29
  const abortTimer = setTimeout(() => aborter.abort(), this.timeout);
36
- const raw = await (0, cross_fetch_1.default)(this.url, {
30
+ const raw = await fetch(this.url, {
37
31
  method: "POST",
38
32
  headers: {
39
33
  "content-type": "application/json",
@@ -60,4 +54,3 @@ class ClientJsonRpc {
60
54
  };
61
55
  }
62
56
  }
63
- exports.ClientJsonRpc = ClientJsonRpc;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.One = exports.Zero = exports.fixedPointFrom = exports.fixedPointToString = void 0;
4
- function fixedPointToString(val, decimals = 8) {
1
+ export function fixedPointToString(val, decimals = 8) {
5
2
  const str = val.toString();
6
3
  const l = str.length <= decimals ? "0" : str.slice(0, -decimals);
7
4
  const r = str.slice(-decimals).padStart(decimals, "0").replace(/0*$/, "");
@@ -10,8 +7,7 @@ function fixedPointToString(val, decimals = 8) {
10
7
  }
11
8
  return `${l}.${r}`;
12
9
  }
13
- exports.fixedPointToString = fixedPointToString;
14
- function fixedPointFrom(val, decimals = 8) {
10
+ export function fixedPointFrom(val, decimals = 8) {
15
11
  if (typeof val === "bigint") {
16
12
  return val;
17
13
  }
@@ -22,6 +18,5 @@ function fixedPointFrom(val, decimals = 8) {
22
18
  }
23
19
  return lVal + BigInt(r.slice(0, decimals).padEnd(decimals, "0"));
24
20
  }
25
- exports.fixedPointFrom = fixedPointFrom;
26
- exports.Zero = 0n;
27
- exports.One = fixedPointFrom("1");
21
+ export const Zero = 0n;
22
+ export const One = fixedPointFrom("1");
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CKB_BLAKE2B_PERSONAL = void 0;
4
- exports.CKB_BLAKE2B_PERSONAL = "ckb-default-hash";
1
+ export const CKB_BLAKE2B_PERSONAL = "ckb-default-hash";
@@ -1,26 +1,18 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ckbHash = exports.Hasher = void 0;
7
- const blake2b_1 = __importDefault(require("blake2b"));
8
- const bytes_1 = require("../bytes");
9
- const advanced_1 = require("./advanced");
10
- class Hasher {
11
- constructor(outLength = 32, personal = advanced_1.CKB_BLAKE2B_PERSONAL) {
12
- this.hasher = (0, blake2b_1.default)(outLength, undefined, undefined, (0, bytes_1.bytesFromUtf8)(personal));
1
+ import blake2b from "blake2b";
2
+ import { bytesFrom, bytesFromUtf8 } from "../bytes";
3
+ import { CKB_BLAKE2B_PERSONAL } from "./advanced";
4
+ export class Hasher {
5
+ constructor(outLength = 32, personal = CKB_BLAKE2B_PERSONAL) {
6
+ this.hasher = blake2b(outLength, undefined, undefined, bytesFromUtf8(personal));
13
7
  }
14
8
  update(data) {
15
- this.hasher.update((0, bytes_1.bytesFrom)(data));
9
+ this.hasher.update(bytesFrom(data));
16
10
  return this;
17
11
  }
18
12
  digest() {
19
13
  return `0x${this.hasher.digest("hex")}`;
20
14
  }
21
15
  }
22
- exports.Hasher = Hasher;
23
- function ckbHash(data) {
16
+ export function ckbHash(data) {
24
17
  return new Hasher().update(data).digest();
25
18
  }
26
- exports.ckbHash = ckbHash;
package/dist/hex/index.js CHANGED
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hexFrom = void 0;
4
- const buffer_1 = require("buffer/");
5
- const bytes_1 = require("../bytes");
6
- function hexFrom(hex) {
7
- return `0x${buffer_1.Buffer.from((0, bytes_1.bytesFrom)(hex)).toString("hex")}`;
1
+ import { Buffer } from "buffer/";
2
+ import { bytesFrom } from "../bytes";
3
+ export function hexFrom(hex) {
4
+ return `0x${Buffer.from(bytesFrom(hex)).toString("hex")}`;
8
5
  }
9
- exports.hexFrom = hexFrom;
package/dist/index.js CHANGED
@@ -1,31 +1,2 @@
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;
17
- });
18
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
- };
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.ccc = void 0;
30
- __exportStar(require("./barrel"), exports);
31
- exports.ccc = __importStar(require("./barrel"));
1
+ export * from "./barrel";
2
+ export * as ccc from "./barrel";
package/dist/num/index.js CHANGED
@@ -1,47 +1,36 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.numBeFromBytes = exports.numLeFromBytes = exports.numFromBytes = exports.numBeToBytes = exports.numLeToBytes = exports.numToBytes = exports.numToHex = exports.numFrom = void 0;
4
- const bytes_1 = require("../bytes");
5
- const hex_1 = require("../hex");
6
- function numFrom(val) {
1
+ import { bytesConcat, bytesFrom } from "../bytes";
2
+ import { hexFrom } from "../hex";
3
+ export function numFrom(val) {
7
4
  if (typeof val === "bigint") {
8
5
  return val;
9
6
  }
10
7
  if (typeof val === "string" || typeof val === "number") {
11
8
  return BigInt(val);
12
9
  }
13
- return BigInt((0, hex_1.hexFrom)(val));
10
+ return BigInt(hexFrom(val));
14
11
  }
15
- exports.numFrom = numFrom;
16
- function numToHex(val) {
12
+ export function numToHex(val) {
17
13
  return `0x${numFrom(val).toString(16)}`;
18
14
  }
19
- exports.numToHex = numToHex;
20
- function numToBytes(val, bytes) {
15
+ export function numToBytes(val, bytes) {
21
16
  return numLeToBytes(val, bytes);
22
17
  }
23
- exports.numToBytes = numToBytes;
24
- function numLeToBytes(val, bytes) {
18
+ export function numLeToBytes(val, bytes) {
25
19
  return numBeToBytes(val, bytes).reverse();
26
20
  }
27
- exports.numLeToBytes = numLeToBytes;
28
- function numBeToBytes(val, bytes) {
29
- const rawBytes = (0, bytes_1.bytesFrom)(numFrom(val).toString(16));
21
+ export function numBeToBytes(val, bytes) {
22
+ const rawBytes = bytesFrom(numFrom(val).toString(16));
30
23
  if (bytes == null) {
31
24
  return rawBytes;
32
25
  }
33
- return (0, bytes_1.bytesConcat)(Array.from(Array(bytes - rawBytes.length), () => 0), rawBytes);
26
+ return bytesConcat(Array.from(Array(bytes - rawBytes.length), () => 0), rawBytes);
34
27
  }
35
- exports.numBeToBytes = numBeToBytes;
36
- function numFromBytes(val) {
28
+ export function numFromBytes(val) {
37
29
  return numLeFromBytes(val);
38
30
  }
39
- exports.numFromBytes = numFromBytes;
40
- function numLeFromBytes(val) {
41
- return numBeFromBytes((0, bytes_1.bytesFrom)(val).reverse());
31
+ export function numLeFromBytes(val) {
32
+ return numBeFromBytes(bytesFrom(val).reverse());
42
33
  }
43
- exports.numLeFromBytes = numLeFromBytes;
44
- function numBeFromBytes(val) {
45
- return numFrom((0, bytes_1.bytesFrom)(val));
34
+ export function numBeFromBytes(val) {
35
+ return numFrom(bytesFrom(val));
46
36
  }
47
- exports.numBeFromBytes = numBeFromBytes;
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSignHashInfo = void 0;
4
- const ckb_1 = require("../ckb");
5
- const hasher_1 = require("../hasher");
6
- async function getSignHashInfo(txLike, scriptLike) {
7
- const tx = ckb_1.Transaction.from(txLike);
8
- const script = ckb_1.Script.from(scriptLike);
1
+ import { Script, Transaction } from "../ckb";
2
+ import { Hasher } from "../hasher";
3
+ export async function getSignHashInfo(txLike, scriptLike) {
4
+ const tx = Transaction.from(txLike);
5
+ const script = Script.from(scriptLike);
9
6
  let position = -1;
10
- const hasher = new hasher_1.Hasher();
7
+ const hasher = new Hasher();
11
8
  hasher.update(tx.hash());
12
9
  tx.witnesses.forEach((witness, i) => {
13
10
  const input = tx.inputs[i];
@@ -25,7 +22,7 @@ async function getSignHashInfo(txLike, scriptLike) {
25
22
  if (position === -1) {
26
23
  return undefined;
27
24
  }
28
- ckb_1.Transaction.hashWitnessToHasher(witness, hasher);
25
+ Transaction.hashWitnessToHasher(witness, hasher);
29
26
  });
30
27
  if (position === -1) {
31
28
  return undefined;
@@ -35,4 +32,3 @@ async function getSignHashInfo(txLike, scriptLike) {
35
32
  position,
36
33
  };
37
34
  }
38
- exports.getSignHashInfo = getSignHashInfo;
@@ -1,20 +1,4 @@
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("./helpers"), exports);
18
- __exportStar(require("./signer"), exports);
19
- __exportStar(require("./signerReadonly"), exports);
20
- __exportStar(require("./signerReadonlyCkbScript"), exports);
1
+ export * from "./helpers";
2
+ export * from "./signer";
3
+ export * from "./signerReadonly";
4
+ export * from "./signerReadonlyCkbScript";
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Signer = void 0;
4
- class Signer {
1
+ export class Signer {
5
2
  constructor(client) {
6
3
  this.client = client;
7
4
  }
@@ -21,4 +18,3 @@ class Signer {
21
18
  return this.signOnlyTransaction(tx);
22
19
  }
23
20
  }
24
- exports.Signer = Signer;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SignerReadonly = void 0;
4
- const _1 = require(".");
5
- class SignerReadonly extends _1.Signer {
1
+ import { Signer } from ".";
2
+ export class SignerReadonly extends Signer {
6
3
  signMessage() {
7
4
  throw new Error("Method not implemented.");
8
5
  }
@@ -10,4 +7,3 @@ class SignerReadonly extends _1.Signer {
10
7
  throw new Error("Method not implemented.");
11
8
  }
12
9
  }
13
- exports.SignerReadonly = SignerReadonly;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SignerReadonlyCkbScript = void 0;
4
- const address_1 = require("../address");
5
- const signerReadonly_1 = require("./signerReadonly");
6
- class SignerReadonlyCkbScript extends signerReadonly_1.SignerReadonly {
1
+ import { Address } from "../address";
2
+ import { SignerReadonly } from "./signerReadonly";
3
+ export class SignerReadonlyCkbScript extends SignerReadonly {
7
4
  constructor(script, client) {
8
5
  super(client);
9
6
  this.script = script;
@@ -15,7 +12,6 @@ class SignerReadonlyCkbScript extends signerReadonly_1.SignerReadonly {
15
12
  return this.getRecommendedAddress();
16
13
  }
17
14
  async getAddressObjs() {
18
- return [await address_1.Address.fromScript(this.script, this.client)];
15
+ return [await Address.fromScript(this.script, this.client)];
19
16
  }
20
17
  }
21
- exports.SignerReadonlyCkbScript = SignerReadonlyCkbScript;
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.apply = void 0;
4
- function apply(transformer, value) {
1
+ export function apply(transformer, value) {
5
2
  if (value == null) {
6
3
  return value;
7
4
  }
8
5
  return transformer(value);
9
6
  }
10
- exports.apply = apply;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/core",
3
- "version": "0.0.2-alpha.3",
3
+ "version": "0.0.2",
4
4
  "description": "Common Chains Connector Core",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -41,5 +41,5 @@
41
41
  "buffer": "^6.0.3",
42
42
  "cross-fetch": "^4.0.0"
43
43
  },
44
- "gitHead": "32c720f568bc39ba31e0ef00e86fe9173f76e4bf"
44
+ "gitHead": "34b7f8d8443258188d47aad71246e787b544300b"
45
45
  }
@@ -11,6 +11,8 @@ export enum KnownScript {
11
11
  }
12
12
 
13
13
  export interface Client {
14
+ getUrl(): string;
15
+
14
16
  getAddressPrefix(): Promise<string>;
15
17
  getKnownScript(script: KnownScript): Promise<Omit<ScriptLike, "args">>;
16
18