@ckb-ccc/core 0.0.2-alpha.2 → 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.
- package/.prettierignore +12 -0
- package/dist/address/address.advanced.d.ts +29 -3
- package/dist/address/address.advanced.d.ts.map +1 -1
- package/dist/address/address.advanced.js +70 -28
- package/dist/address/advanced.d.ts +1 -28
- package/dist/address/advanced.d.ts.map +1 -1
- package/dist/address/advanced.js +1 -75
- package/dist/address/index.d.ts +10 -13
- package/dist/address/index.d.ts.map +1 -1
- package/dist/address/index.js +21 -25
- package/dist/advanced.js +2 -31
- package/dist/advancedBarrel.d.ts +1 -0
- package/dist/advancedBarrel.d.ts.map +1 -1
- package/dist/advancedBarrel.js +4 -19
- package/dist/barrel.d.ts +4 -2
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +10 -24
- package/dist/bytes/index.d.ts +7 -0
- package/dist/bytes/index.d.ts.map +1 -0
- package/dist/bytes/index.js +34 -0
- package/dist/ckb/advanced.d.ts +3 -2
- package/dist/ckb/advanced.d.ts.map +1 -1
- package/dist/ckb/advanced.js +3 -18
- package/dist/ckb/index.d.ts +2 -3
- package/dist/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +2 -19
- package/dist/ckb/molecule.advanced/generated.d.ts.map +1 -0
- package/dist/ckb/{types/molecule.advanced → molecule.advanced}/generated.js +444 -231
- package/dist/ckb/molecule.advanced/index.d.ts +6 -0
- package/dist/ckb/molecule.advanced/index.d.ts.map +1 -0
- package/dist/ckb/molecule.advanced/index.js +7 -0
- package/dist/ckb/{types/script.advanced.d.ts → script.advanced.d.ts} +1 -0
- package/dist/ckb/script.advanced.d.ts.map +1 -0
- package/dist/ckb/script.advanced.js +13 -0
- package/dist/ckb/script.d.ts +29 -0
- package/dist/ckb/script.d.ts.map +1 -0
- package/dist/ckb/script.js +61 -0
- package/dist/ckb/{types/transaction.advanced.d.ts → transaction.advanced.d.ts} +1 -0
- package/dist/ckb/transaction.advanced.d.ts.map +1 -0
- package/dist/ckb/transaction.advanced.js +9 -0
- package/dist/ckb/transaction.d.ts +142 -0
- package/dist/ckb/transaction.d.ts.map +1 -0
- package/dist/ckb/transaction.js +227 -0
- package/dist/client/advanced.js +2 -18
- package/dist/client/client.d.ts +5 -4
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +2 -5
- package/dist/client/clientPublicMainnet.advanced.d.ts +2 -2
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.js +7 -10
- package/dist/client/clientPublicMainnet.d.ts +2 -2
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.js +4 -8
- package/dist/client/clientPublicTestnet.advanced.d.ts +2 -2
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.advanced.js +7 -10
- package/dist/client/clientPublicTestnet.d.ts +2 -2
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.js +4 -8
- package/dist/client/clientTypes.js +1 -2
- package/dist/client/index.js +4 -20
- package/dist/client/jsonRpc/advanced.d.ts +36 -36
- package/dist/client/jsonRpc/advanced.d.ts.map +1 -1
- package/dist/client/jsonRpc/advanced.js +13 -17
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +5 -13
- package/dist/fixedPoint/index.d.ts +7 -0
- package/dist/fixedPoint/index.d.ts.map +1 -0
- package/dist/fixedPoint/index.js +22 -0
- package/dist/{ckb/hasher.advanced.d.ts → hasher/advanced.d.ts} +1 -1
- package/dist/hasher/advanced.d.ts.map +1 -0
- package/dist/{ckb/hasher.d.ts → hasher/index.d.ts} +3 -2
- package/dist/hasher/index.d.ts.map +1 -0
- package/dist/hasher/index.js +18 -0
- package/dist/hex/index.d.ts +5 -0
- package/dist/hex/index.d.ts.map +1 -0
- package/dist/hex/index.js +5 -0
- package/dist/index.js +2 -31
- package/dist/num/index.d.ts +13 -0
- package/dist/num/index.d.ts.map +1 -0
- package/dist/num/index.js +36 -0
- package/dist/signer/helpers.d.ts +3 -3
- package/dist/signer/helpers.d.ts.map +1 -1
- package/dist/signer/helpers.js +9 -10
- package/dist/signer/index.d.ts +2 -0
- package/dist/signer/index.d.ts.map +1 -1
- package/dist/signer/index.js +4 -18
- package/dist/signer/signer.d.ts +12 -3
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/signer/signer.js +13 -6
- package/dist/signer/signerReadonly.d.ts +8 -0
- package/dist/signer/signerReadonly.d.ts.map +1 -0
- package/dist/signer/signerReadonly.js +9 -0
- package/dist/{ckb/viewerCkbScript.d.ts → signer/signerReadonlyCkbScript.d.ts} +6 -5
- package/dist/signer/signerReadonlyCkbScript.d.ts.map +1 -0
- package/dist/signer/signerReadonlyCkbScript.js +17 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +6 -0
- package/package.json +5 -3
- package/src/address/address.advanced.ts +76 -19
- package/src/address/advanced.ts +1 -59
- package/src/address/index.ts +46 -28
- package/src/advancedBarrel.ts +1 -0
- package/src/barrel.ts +4 -2
- package/src/bytes/index.ts +46 -0
- package/src/ckb/advanced.ts +3 -2
- package/src/ckb/index.ts +2 -3
- package/src/ckb/{types/molecule.advanced → molecule.advanced}/generated.d.ts +18 -7
- package/src/ckb/{types/molecule.advanced → molecule.advanced}/generated.js +551 -123
- package/src/ckb/molecule.advanced/index.ts +11 -0
- package/src/ckb/{types/script.advanced.ts → script.advanced.ts} +1 -0
- package/src/ckb/script.ts +94 -0
- package/src/ckb/{types/transaction.advanced.ts → transaction.advanced.ts} +1 -0
- package/src/ckb/transaction.ts +357 -0
- package/src/client/client.ts +6 -4
- package/src/client/clientPublicMainnet.advanced.ts +2 -2
- package/src/client/clientPublicMainnet.ts +2 -2
- package/src/client/clientPublicTestnet.advanced.ts +2 -2
- package/src/client/clientPublicTestnet.ts +2 -2
- package/src/client/clientTypes.ts +1 -1
- package/src/client/jsonRpc/advanced.ts +25 -25
- package/src/client/jsonRpc/index.ts +1 -3
- package/src/fixedPoint/index.ts +30 -0
- package/src/hasher/advanced.ts +1 -0
- package/src/{ckb/hasher.ts → hasher/index.ts} +5 -5
- package/src/hex/index.ts +9 -0
- package/src/index.ts +1 -1
- package/src/num/index.ts +53 -0
- package/src/signer/helpers.ts +9 -6
- package/src/signer/index.ts +3 -1
- package/src/signer/signer.ts +23 -3
- package/src/signer/signerReadonly.ts +13 -0
- package/src/{ckb/viewerCkbScript.ts → signer/signerReadonlyCkbScript.ts} +8 -4
- package/src/utils/index.ts +28 -0
- package/dist/bytes.d.ts +0 -15
- package/dist/bytes.d.ts.map +0 -1
- package/dist/bytes.js +0 -114
- package/dist/ckb/hasher.advanced.d.ts.map +0 -1
- package/dist/ckb/hasher.advanced.js +0 -4
- package/dist/ckb/hasher.d.ts.map +0 -1
- package/dist/ckb/hasher.js +0 -26
- package/dist/ckb/types/advanced.d.ts +0 -4
- package/dist/ckb/types/advanced.d.ts.map +0 -1
- package/dist/ckb/types/advanced.js +0 -32
- package/dist/ckb/types/index.d.ts +0 -3
- package/dist/ckb/types/index.d.ts.map +0 -1
- package/dist/ckb/types/index.js +0 -18
- package/dist/ckb/types/molecule.advanced/generated.d.ts.map +0 -1
- package/dist/ckb/types/molecule.advanced/index.d.ts +0 -2
- package/dist/ckb/types/molecule.advanced/index.d.ts.map +0 -1
- package/dist/ckb/types/molecule.advanced/index.js +0 -17
- package/dist/ckb/types/script.advanced.d.ts.map +0 -1
- package/dist/ckb/types/script.advanced.js +0 -15
- package/dist/ckb/types/script.d.ts +0 -26
- package/dist/ckb/types/script.d.ts.map +0 -1
- package/dist/ckb/types/script.js +0 -75
- package/dist/ckb/types/transaction.advanced.d.ts.map +0 -1
- package/dist/ckb/types/transaction.advanced.js +0 -11
- package/dist/ckb/types/transaction.d.ts +0 -127
- package/dist/ckb/types/transaction.d.ts.map +0 -1
- package/dist/ckb/types/transaction.js +0 -266
- package/dist/ckb/viewerCkbScript.d.ts.map +0 -1
- package/dist/ckb/viewerCkbScript.js +0 -18
- package/dist/fixedPoint.d.ts +0 -9
- package/dist/fixedPoint.d.ts.map +0 -1
- package/dist/fixedPoint.js +0 -30
- package/dist/primitive.d.ts +0 -5
- package/dist/primitive.d.ts.map +0 -1
- package/dist/primitive.js +0 -2
- package/dist/viewer.d.ts +0 -12
- package/dist/viewer.d.ts.map +0 -1
- package/dist/viewer.js +0 -19
- package/src/bytes.ts +0 -127
- package/src/ckb/types/advanced.ts +0 -3
- package/src/ckb/types/index.ts +0 -2
- package/src/ckb/types/molecule.advanced/index.ts +0 -1
- package/src/ckb/types/script.ts +0 -70
- package/src/ckb/types/transaction.ts +0 -366
- package/src/fixedPoint.ts +0 -53
- package/src/primitive.ts +0 -8
- package/src/viewer.ts +0 -22
- /package/dist/ckb/{types/molecule.advanced → molecule.advanced}/generated.d.ts +0 -0
- /package/{src/ckb/hasher.advanced.ts → dist/hasher/advanced.js} +0 -0
- /package/src/ckb/{types/molecule.advanced → molecule.advanced}/blockchain.mol +0 -0
package/dist/signer/helpers.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
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);
|
|
6
6
|
let position = -1;
|
|
7
|
-
const hasher = new
|
|
8
|
-
hasher.update(
|
|
7
|
+
const hasher = new Hasher();
|
|
8
|
+
hasher.update(tx.hash());
|
|
9
9
|
tx.witnesses.forEach((witness, i) => {
|
|
10
10
|
const input = tx.inputs[i];
|
|
11
11
|
if (input) {
|
|
12
12
|
if (!input.cellOutput?.lock) {
|
|
13
13
|
throw Error("Incomplete inputs info");
|
|
14
14
|
}
|
|
15
|
-
if (!
|
|
15
|
+
if (!script.eq(input.cellOutput?.lock)) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
if (position === -1) {
|
|
@@ -22,7 +22,7 @@ async function getSignHashInfo(tx, script) {
|
|
|
22
22
|
if (position === -1) {
|
|
23
23
|
return undefined;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
Transaction.hashWitnessToHasher(witness, hasher);
|
|
26
26
|
});
|
|
27
27
|
if (position === -1) {
|
|
28
28
|
return undefined;
|
|
@@ -32,4 +32,3 @@ async function getSignHashInfo(tx, script) {
|
|
|
32
32
|
position,
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
exports.getSignHashInfo = getSignHashInfo;
|
package/dist/signer/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signer/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signer/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC"}
|
package/dist/signer/index.js
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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);
|
|
1
|
+
export * from "./helpers";
|
|
2
|
+
export * from "./signer";
|
|
3
|
+
export * from "./signerReadonly";
|
|
4
|
+
export * from "./signerReadonlyCkbScript";
|
package/dist/signer/signer.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BytesLike
|
|
1
|
+
import { Address } from "../address";
|
|
2
|
+
import { BytesLike } from "../bytes";
|
|
3
3
|
import { Transaction } from "../ckb";
|
|
4
|
-
|
|
4
|
+
import { Client } from "../client";
|
|
5
|
+
import { Hex } from "../hex";
|
|
6
|
+
export declare abstract class Signer {
|
|
7
|
+
readonly client: Client;
|
|
8
|
+
constructor(client: Client);
|
|
5
9
|
abstract connect(): Promise<void>;
|
|
10
|
+
abstract getInternalAddress(): Promise<string>;
|
|
11
|
+
abstract getAddressObjs(): Promise<Address[]>;
|
|
12
|
+
getRecommendedAddressObj(_preference?: unknown): Promise<Address>;
|
|
13
|
+
getRecommendedAddress(preference?: unknown): Promise<string>;
|
|
14
|
+
getAddresses(): Promise<string[]>;
|
|
6
15
|
abstract signMessage(message: string | BytesLike): Promise<Hex>;
|
|
7
16
|
sendTransaction(tx: Transaction): Promise<Hex>;
|
|
8
17
|
signTransaction(tx: Transaction): Promise<Transaction>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signer/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signer/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B,8BAAsB,MAAM;aACE,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM;IAE1C,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAEjC,QAAQ,CAAC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAE9C,QAAQ,CAAC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IACvC,wBAAwB,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjE,qBAAqB,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAG5D,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAMvC,QAAQ,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC;IAEzD,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAI9C,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAI5D,QAAQ,CAAC,mBAAmB,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;CACpE"}
|
package/dist/signer/signer.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export class Signer {
|
|
2
|
+
constructor(client) {
|
|
3
|
+
this.client = client;
|
|
4
|
+
}
|
|
5
|
+
async getRecommendedAddressObj(_preference) {
|
|
6
|
+
return (await this.getAddressObjs())[0];
|
|
7
|
+
}
|
|
8
|
+
async getRecommendedAddress(preference) {
|
|
9
|
+
return (await this.getRecommendedAddressObj(preference)).toString();
|
|
10
|
+
}
|
|
11
|
+
async getAddresses() {
|
|
12
|
+
return this.getAddressObjs().then((addresses) => addresses.map((address) => address.toString()));
|
|
13
|
+
}
|
|
6
14
|
async sendTransaction(tx) {
|
|
7
15
|
return this.client.sendTransaction(await this.signTransaction(tx));
|
|
8
16
|
}
|
|
@@ -10,4 +18,3 @@ class Signer extends viewer_1.Viewer {
|
|
|
10
18
|
return this.signOnlyTransaction(tx);
|
|
11
19
|
}
|
|
12
20
|
}
|
|
13
|
-
exports.Signer = Signer;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Signer } from ".";
|
|
2
|
+
import { Transaction } from "../ckb";
|
|
3
|
+
import { Hex } from "../hex";
|
|
4
|
+
export declare abstract class SignerReadonly extends Signer {
|
|
5
|
+
signMessage(): Promise<Hex>;
|
|
6
|
+
signOnlyTransaction(): Promise<Transaction>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=signerReadonly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signerReadonly.d.ts","sourceRoot":"","sources":["../../src/signer/signerReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B,8BAAsB,cAAe,SAAQ,MAAM;IACjD,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC;IAI3B,mBAAmB,IAAI,OAAO,CAAC,WAAW,CAAC;CAG5C"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Client } from "../client";
|
|
2
|
-
import { Script } from "./types";
|
|
3
|
-
import { Viewer } from "../viewer";
|
|
4
1
|
import { Address } from "../address";
|
|
5
|
-
|
|
2
|
+
import { Script } from "../ckb";
|
|
3
|
+
import { Client } from "../client";
|
|
4
|
+
import { SignerReadonly } from "./signerReadonly";
|
|
5
|
+
export declare class SignerReadonlyCkbScript extends SignerReadonly {
|
|
6
6
|
private readonly script;
|
|
7
7
|
constructor(script: Script, client: Client);
|
|
8
|
+
connect(): Promise<void>;
|
|
8
9
|
getInternalAddress(): Promise<string>;
|
|
9
10
|
getAddressObjs(): Promise<Address[]>;
|
|
10
11
|
}
|
|
11
|
-
//# sourceMappingURL=
|
|
12
|
+
//# sourceMappingURL=signerReadonlyCkbScript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signerReadonlyCkbScript.d.ts","sourceRoot":"","sources":["../../src/signer/signerReadonlyCkbScript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,qBAAa,uBAAwB,SAAQ,cAAc;IAEvD,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM,EAC/B,MAAM,EAAE,MAAM;IAKV,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAG3C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Address } from "../address";
|
|
2
|
+
import { SignerReadonly } from "./signerReadonly";
|
|
3
|
+
export class SignerReadonlyCkbScript extends SignerReadonly {
|
|
4
|
+
constructor(script, client) {
|
|
5
|
+
super(client);
|
|
6
|
+
this.script = script;
|
|
7
|
+
}
|
|
8
|
+
async connect() {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
async getInternalAddress() {
|
|
12
|
+
return this.getRecommendedAddress();
|
|
13
|
+
}
|
|
14
|
+
async getAddressObjs() {
|
|
15
|
+
return [await Address.fromScript(this.script, this.client)];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function apply<T, R>(transformer: (val: T) => R, value: undefined): undefined;
|
|
2
|
+
export declare function apply<T, R>(transformer: (val: T) => R, value: null): null;
|
|
3
|
+
export declare function apply<T, R>(transformer: (val: T) => R, value: T): R;
|
|
4
|
+
export declare function apply<T, R>(transformer: (val: T) => R, value: T | undefined): R | undefined;
|
|
5
|
+
export declare function apply<T, R>(transformer: (val: T) => R, value: T | null): R | null;
|
|
6
|
+
export declare function apply<T, R>(transformer: (val: T) => R, value: undefined | null): undefined | null;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,SAAS,GACf,SAAS,CAAC;AACb,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,CAAC;AAC3E,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;AACrE,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,CAAC,GAAG,SAAS,GACnB,CAAC,GAAG,SAAS,CAAC;AACjB,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,CAAC,GAAG,IAAI,GACd,CAAC,GAAG,IAAI,CAAC;AACZ,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,SAAS,GAAG,IAAI,GACtB,SAAS,GAAG,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/core",
|
|
3
|
-
"version": "0.0.2
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Common Chains Connector Core",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "rimraf ./dist && tsc",
|
|
17
|
-
"lint": "eslint
|
|
17
|
+
"lint": "eslint",
|
|
18
|
+
"format": "prettier --write . && eslint --fix"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"@ckb-lumos/helpers": "^0.22.2",
|
|
@@ -24,6 +25,7 @@
|
|
|
24
25
|
"eslint-config-prettier": "^9.1.0",
|
|
25
26
|
"eslint-plugin-prettier": "^5.1.3",
|
|
26
27
|
"prettier": "^3.2.5",
|
|
28
|
+
"prettier-plugin-organize-imports": "^3.2.4",
|
|
27
29
|
"rimraf": "^5.0.5",
|
|
28
30
|
"ts-essentials": "^9.4.2",
|
|
29
31
|
"typescript": "^5.4.5",
|
|
@@ -39,5 +41,5 @@
|
|
|
39
41
|
"buffer": "^6.0.3",
|
|
40
42
|
"cross-fetch": "^4.0.0"
|
|
41
43
|
},
|
|
42
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "34b7f8d8443258188d47aad71246e787b544300b"
|
|
43
45
|
}
|
|
@@ -1,27 +1,60 @@
|
|
|
1
|
+
import { bech32, bech32m } from "bech32";
|
|
2
|
+
import { hashTypeFromBytes } from "../ckb";
|
|
1
3
|
import { Client, KnownScript } from "../client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { type Address as AddressType } from "./index";
|
|
5
|
-
import { decodeHashType } from "../ckb";
|
|
4
|
+
import { hexFrom } from "../hex";
|
|
5
|
+
import { type AddressLike } from "./index";
|
|
6
6
|
|
|
7
|
-
export
|
|
7
|
+
export function addressPayloadFromString(address: string): {
|
|
8
|
+
prefix: string;
|
|
9
|
+
format: AddressFormat;
|
|
10
|
+
payload: number[];
|
|
11
|
+
} {
|
|
12
|
+
// Try parse full format address
|
|
13
|
+
{
|
|
14
|
+
const { words, prefix } = bech32m.decode(address, ADDRESS_BECH32_LIMIT);
|
|
15
|
+
const [formatType, ...payload] = bech32m.fromWords(words);
|
|
16
|
+
|
|
17
|
+
if (formatType === (AddressFormat.Full as number)) {
|
|
18
|
+
return { prefix, format: AddressFormat.Full, payload };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Try parse legacy 2019 format address
|
|
23
|
+
{
|
|
24
|
+
const { prefix, words } = bech32.decode(address, ADDRESS_BECH32_LIMIT);
|
|
25
|
+
const [formatType, ...payload] = bech32.fromWords(words);
|
|
26
|
+
if (
|
|
27
|
+
[
|
|
28
|
+
AddressFormat.FullData,
|
|
29
|
+
AddressFormat.FullType,
|
|
30
|
+
AddressFormat.Short,
|
|
31
|
+
].includes(formatType)
|
|
32
|
+
) {
|
|
33
|
+
return { prefix, format: formatType, payload };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
throw Error(`Unknown address format ${address}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function addressFromPayload(
|
|
8
41
|
prefix: string,
|
|
9
42
|
format: AddressFormat,
|
|
10
43
|
payload: number[],
|
|
11
44
|
client: Client,
|
|
12
|
-
): Promise<
|
|
45
|
+
): Promise<AddressLike> {
|
|
13
46
|
if (format === AddressFormat.Full) {
|
|
14
47
|
if (payload.length < 32 + 1) {
|
|
15
48
|
throw new Error(
|
|
16
|
-
`Invalid full address without enough payload ${
|
|
49
|
+
`Invalid full address without enough payload ${hexFrom(payload)}`,
|
|
17
50
|
);
|
|
18
51
|
}
|
|
19
52
|
|
|
20
53
|
return {
|
|
21
54
|
script: {
|
|
22
|
-
codeHash:
|
|
23
|
-
hashType:
|
|
24
|
-
args:
|
|
55
|
+
codeHash: hexFrom(payload.slice(0, 32)),
|
|
56
|
+
hashType: hashTypeFromBytes(payload.slice(32, 33)),
|
|
57
|
+
args: hexFrom(payload.slice(33)),
|
|
25
58
|
},
|
|
26
59
|
prefix,
|
|
27
60
|
};
|
|
@@ -30,15 +63,15 @@ export async function fromAddressPayload(
|
|
|
30
63
|
if (format === AddressFormat.FullData) {
|
|
31
64
|
if (payload.length < 32) {
|
|
32
65
|
throw new Error(
|
|
33
|
-
`Invalid full data address without enough payload ${
|
|
66
|
+
`Invalid full data address without enough payload ${hexFrom(payload)}`,
|
|
34
67
|
);
|
|
35
68
|
}
|
|
36
69
|
|
|
37
70
|
return {
|
|
38
71
|
script: {
|
|
39
|
-
codeHash:
|
|
72
|
+
codeHash: hexFrom(payload.slice(0, 32)),
|
|
40
73
|
hashType: "data",
|
|
41
|
-
args:
|
|
74
|
+
args: hexFrom(payload.slice(32)),
|
|
42
75
|
},
|
|
43
76
|
prefix,
|
|
44
77
|
};
|
|
@@ -47,15 +80,15 @@ export async function fromAddressPayload(
|
|
|
47
80
|
if (format === AddressFormat.FullType) {
|
|
48
81
|
if (payload.length < 32) {
|
|
49
82
|
throw new Error(
|
|
50
|
-
`Invalid full type address without enough payload ${
|
|
83
|
+
`Invalid full type address without enough payload ${hexFrom(payload)}`,
|
|
51
84
|
);
|
|
52
85
|
}
|
|
53
86
|
|
|
54
87
|
return {
|
|
55
88
|
script: {
|
|
56
|
-
codeHash:
|
|
89
|
+
codeHash: hexFrom(payload.slice(0, 32)),
|
|
57
90
|
hashType: "type",
|
|
58
|
-
args:
|
|
91
|
+
args: hexFrom(payload.slice(32)),
|
|
59
92
|
},
|
|
60
93
|
prefix,
|
|
61
94
|
};
|
|
@@ -64,7 +97,7 @@ export async function fromAddressPayload(
|
|
|
64
97
|
// format === AddressFormat.Short
|
|
65
98
|
if (payload.length !== 21) {
|
|
66
99
|
throw new Error(
|
|
67
|
-
`Invalid short address without enough payload ${
|
|
100
|
+
`Invalid short address without enough payload ${hexFrom(payload)}`,
|
|
68
101
|
);
|
|
69
102
|
}
|
|
70
103
|
const script = [
|
|
@@ -74,15 +107,39 @@ export async function fromAddressPayload(
|
|
|
74
107
|
][payload[0]];
|
|
75
108
|
if (script === undefined) {
|
|
76
109
|
throw new Error(
|
|
77
|
-
`Invalid short address with unknown script ${
|
|
110
|
+
`Invalid short address with unknown script ${hexFrom(payload)}`,
|
|
78
111
|
);
|
|
79
112
|
}
|
|
80
113
|
|
|
81
114
|
return {
|
|
82
115
|
script: {
|
|
83
116
|
...(await client.getKnownScript(script)),
|
|
84
|
-
args:
|
|
117
|
+
args: hexFrom(payload.slice(1)),
|
|
85
118
|
},
|
|
86
119
|
prefix,
|
|
87
120
|
};
|
|
88
121
|
}
|
|
122
|
+
|
|
123
|
+
export enum AddressFormat {
|
|
124
|
+
/**
|
|
125
|
+
* full version identifies the hashType
|
|
126
|
+
*/
|
|
127
|
+
Full = 0x00,
|
|
128
|
+
/**
|
|
129
|
+
* @deprecated
|
|
130
|
+
* short version for locks with Known codeHash, deprecated
|
|
131
|
+
*/
|
|
132
|
+
Short = 0x01,
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated
|
|
135
|
+
* full version with hashType = "Data", deprecated
|
|
136
|
+
*/
|
|
137
|
+
FullData = 0x02,
|
|
138
|
+
/**
|
|
139
|
+
* @deprecated
|
|
140
|
+
* full version with hashType = "Type", deprecated
|
|
141
|
+
*/
|
|
142
|
+
FullType = 0x04,
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const ADDRESS_BECH32_LIMIT = 1023;
|
package/src/address/advanced.ts
CHANGED
|
@@ -1,59 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export * as Address from "./address.advanced";
|
|
3
|
-
|
|
4
|
-
export function parseAddressToPayload(address: string): {
|
|
5
|
-
prefix: string;
|
|
6
|
-
format: AddressFormat;
|
|
7
|
-
payload: number[];
|
|
8
|
-
} {
|
|
9
|
-
// Try parse full format address
|
|
10
|
-
{
|
|
11
|
-
const { words, prefix } = bech32m.decode(address, BECH32_LIMIT);
|
|
12
|
-
const [formatType, ...payload] = bech32m.fromWords(words);
|
|
13
|
-
|
|
14
|
-
if (formatType === (AddressFormat.Full as number)) {
|
|
15
|
-
return { prefix, format: AddressFormat.Full, payload };
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Try parse legacy 2019 format address
|
|
20
|
-
{
|
|
21
|
-
const { prefix, words } = bech32.decode(address, BECH32_LIMIT);
|
|
22
|
-
const [formatType, ...payload] = bech32.fromWords(words);
|
|
23
|
-
if (
|
|
24
|
-
[
|
|
25
|
-
AddressFormat.FullData,
|
|
26
|
-
AddressFormat.FullType,
|
|
27
|
-
AddressFormat.Short,
|
|
28
|
-
].includes(formatType)
|
|
29
|
-
) {
|
|
30
|
-
return { prefix, format: formatType, payload };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
throw Error(`Unknown address format ${address}`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export enum AddressFormat {
|
|
38
|
-
/**
|
|
39
|
-
* full version identifies the hashType
|
|
40
|
-
*/
|
|
41
|
-
Full = 0x00,
|
|
42
|
-
/**
|
|
43
|
-
* @deprecated
|
|
44
|
-
* short version for locks with Known codeHash, deprecated
|
|
45
|
-
*/
|
|
46
|
-
Short = 0x01,
|
|
47
|
-
/**
|
|
48
|
-
* @deprecated
|
|
49
|
-
* full version with hashType = "Data", deprecated
|
|
50
|
-
*/
|
|
51
|
-
FullData = 0x02,
|
|
52
|
-
/**
|
|
53
|
-
* @deprecated
|
|
54
|
-
* full version with hashType = "Type", deprecated
|
|
55
|
-
*/
|
|
56
|
-
FullType = 0x04,
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const BECH32_LIMIT = 1023;
|
|
1
|
+
export * from "./address.advanced";
|
package/src/address/index.ts
CHANGED
|
@@ -1,27 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bech32m } from "bech32";
|
|
2
|
+
import { bytesConcat, bytesFrom } from "../bytes";
|
|
3
|
+
import { Script, ScriptLike, hashTypeToBytes } from "../ckb";
|
|
2
4
|
import { Client, KnownScript } from "../client";
|
|
3
|
-
import {
|
|
5
|
+
import { HexLike } from "../hex";
|
|
4
6
|
import {
|
|
7
|
+
ADDRESS_BECH32_LIMIT,
|
|
5
8
|
AddressFormat,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "./advanced";
|
|
10
|
-
import { bech32m } from "bech32";
|
|
11
|
-
import { Hex } from "../primitive";
|
|
12
|
-
import { concatBytes, toBytes } from "../bytes";
|
|
9
|
+
addressFromPayload,
|
|
10
|
+
addressPayloadFromString,
|
|
11
|
+
} from "./address.advanced";
|
|
13
12
|
|
|
13
|
+
export type AddressLike = {
|
|
14
|
+
script: ScriptLike;
|
|
15
|
+
prefix: string;
|
|
16
|
+
};
|
|
14
17
|
export class Address {
|
|
15
18
|
constructor(
|
|
16
19
|
public script: Script,
|
|
17
20
|
public prefix: string,
|
|
18
21
|
) {}
|
|
19
22
|
|
|
23
|
+
static from(address: AddressLike): Address {
|
|
24
|
+
if (address instanceof Address) {
|
|
25
|
+
return address;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return new Address(Script.from(address.script), address.prefix);
|
|
29
|
+
}
|
|
30
|
+
|
|
20
31
|
static async fromString(
|
|
21
32
|
address: string,
|
|
22
33
|
clients: Client | Record<string, Client>,
|
|
23
34
|
): Promise<Address> {
|
|
24
|
-
const { prefix, format, payload } =
|
|
35
|
+
const { prefix, format, payload } = addressPayloadFromString(address);
|
|
25
36
|
|
|
26
37
|
const client = (clients as Record<string, Client>)[prefix] ?? clients;
|
|
27
38
|
if (!client) {
|
|
@@ -34,37 +45,44 @@ export class Address {
|
|
|
34
45
|
);
|
|
35
46
|
}
|
|
36
47
|
|
|
37
|
-
return
|
|
48
|
+
return Address.from(
|
|
49
|
+
await addressFromPayload(prefix, format, payload, client),
|
|
50
|
+
);
|
|
38
51
|
}
|
|
39
52
|
|
|
40
53
|
static async fromScript(
|
|
41
|
-
script:
|
|
54
|
+
script: ScriptLike,
|
|
42
55
|
client: Client,
|
|
43
56
|
): Promise<Address> {
|
|
44
|
-
return
|
|
45
|
-
script: { ...script },
|
|
46
|
-
prefix: await client.getAddressPrefix(),
|
|
47
|
-
};
|
|
57
|
+
return new Address(Script.from(script), await client.getAddressPrefix());
|
|
48
58
|
}
|
|
49
59
|
|
|
50
|
-
static async fromKnownScript(
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
static async fromKnownScript(
|
|
61
|
+
script: KnownScript,
|
|
62
|
+
args: HexLike,
|
|
63
|
+
client: Client,
|
|
64
|
+
) {
|
|
65
|
+
return new Address(
|
|
66
|
+
Script.from({
|
|
53
67
|
...(await client.getKnownScript(script)),
|
|
54
68
|
args,
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
|
|
69
|
+
}),
|
|
70
|
+
await client.getAddressPrefix(),
|
|
71
|
+
);
|
|
58
72
|
}
|
|
59
73
|
|
|
60
|
-
|
|
61
|
-
const data =
|
|
74
|
+
toString(): string {
|
|
75
|
+
const data = bytesConcat(
|
|
62
76
|
[AddressFormat.Full],
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
77
|
+
bytesFrom(this.script.codeHash),
|
|
78
|
+
hashTypeToBytes(this.script.hashType),
|
|
79
|
+
bytesFrom(this.script.args),
|
|
66
80
|
);
|
|
67
81
|
|
|
68
|
-
return bech32m.encode(
|
|
82
|
+
return bech32m.encode(
|
|
83
|
+
this.prefix,
|
|
84
|
+
bech32m.toWords(data),
|
|
85
|
+
ADDRESS_BECH32_LIMIT,
|
|
86
|
+
);
|
|
69
87
|
}
|
|
70
88
|
}
|
package/src/advancedBarrel.ts
CHANGED
package/src/barrel.ts
CHANGED
|
@@ -3,6 +3,8 @@ export * from "./bytes";
|
|
|
3
3
|
export * from "./ckb";
|
|
4
4
|
export * from "./client";
|
|
5
5
|
export * from "./fixedPoint";
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./hasher";
|
|
7
|
+
export * from "./hex";
|
|
8
|
+
export * from "./num";
|
|
7
9
|
export * from "./signer";
|
|
8
|
-
export * from "./
|
|
10
|
+
export * from "./utils";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Buffer } from "buffer/";
|
|
2
|
+
|
|
3
|
+
export type Bytes = Uint8Array;
|
|
4
|
+
export type BytesLike = string | Uint8Array | ArrayBuffer | number[];
|
|
5
|
+
|
|
6
|
+
export function bytesConcat(...args: BytesLike[]): Bytes {
|
|
7
|
+
return new Uint8Array(
|
|
8
|
+
args.reduce((acc: number[], v) => {
|
|
9
|
+
acc.push(...bytesFrom(v));
|
|
10
|
+
return acc;
|
|
11
|
+
}, []),
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function bytesFromUtf8(val: string): Bytes {
|
|
16
|
+
return Buffer.from(val, "utf-8");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function bytesToUtf8(val: BytesLike): string {
|
|
20
|
+
return Buffer.from(bytesFrom(val)).toString("utf-8");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function bytesFrom(bytes: BytesLike): Bytes {
|
|
24
|
+
if (bytes instanceof Uint8Array) {
|
|
25
|
+
return bytes;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (bytes instanceof ArrayBuffer) {
|
|
29
|
+
return new Uint8Array(bytes);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (Array.isArray(bytes)) {
|
|
33
|
+
if (bytes.some((v) => v < 0 || 0xff < v)) {
|
|
34
|
+
throw new Error(`Invalid bytes ${JSON.stringify(bytes)}`);
|
|
35
|
+
}
|
|
36
|
+
return new Uint8Array(bytes);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const str = bytes.startsWith("0x") ? bytes.slice(2) : bytes;
|
|
40
|
+
const paddedStr = str.length % 2 === 0 ? str : `0${str}`;
|
|
41
|
+
const data = Buffer.from(paddedStr, "hex");
|
|
42
|
+
if (data.length * 2 !== paddedStr.length) {
|
|
43
|
+
throw new Error(`Invalid bytes ${bytes}`);
|
|
44
|
+
}
|
|
45
|
+
return data;
|
|
46
|
+
}
|
package/src/ckb/advanced.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export * as moleculeCodecCkb from "./molecule.advanced";
|
|
2
|
+
export * from "./script.advanced";
|
|
3
|
+
export * from "./transaction.advanced";
|
package/src/ckb/index.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./viewerCkbScript";
|
|
1
|
+
export * from "./script";
|
|
2
|
+
export * from "./transaction";
|