@ckb-ccc/lumos-patches 0.0.5-alpha.2 → 0.0.6-alpha.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.
- package/dist/default.d.ts +15 -0
- package/dist/default.d.ts.map +1 -0
- package/dist/default.js +138 -0
- package/dist/index.d.ts +2 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -86
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +11 -0
- package/dist.commonjs/default.d.ts +15 -0
- package/dist.commonjs/default.d.ts.map +1 -0
- package/dist.commonjs/default.js +143 -0
- package/dist.commonjs/index.d.ts +2 -15
- package/dist.commonjs/index.d.ts.map +1 -1
- package/dist.commonjs/index.js +16 -90
- package/dist.commonjs/utils.d.ts +8 -0
- package/dist.commonjs/utils.d.ts.map +1 -0
- package/dist.commonjs/utils.js +15 -0
- package/package.json +2 -2
- package/src/default.ts +191 -0
- package/src/index.ts +2 -140
- package/src/utils.ts +14 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LockScriptInfo } from "@ckb-lumos/common-scripts";
|
|
2
|
+
import { CellDep, Script } from "@ckb-lumos/base";
|
|
3
|
+
/**
|
|
4
|
+
* Generates custom lock script information.
|
|
5
|
+
* @param {string} codeHash - The code hash of the custom script.
|
|
6
|
+
* @param {CellDep[]} cellDeps - The cell dependencies for the custom script.
|
|
7
|
+
* @returns {LockScriptInfo} The lock script information.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateScriptInfo(codeHash: string, cellDeps: CellDep[], cellDepTypes?: Script[]): LockScriptInfo;
|
|
10
|
+
/**
|
|
11
|
+
* Generates default script information for CCC.
|
|
12
|
+
* @returns {LockScriptInfo[]} An array of lock script information.
|
|
13
|
+
*/
|
|
14
|
+
export declare function generateDefaultScriptInfos(): LockScriptInfo[];
|
|
15
|
+
//# sourceMappingURL=default.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../src/default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EAGL,OAAO,EAGP,MAAM,EACP,MAAM,iBAAiB,CAAC;AA8EzB;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EAAE,EACnB,YAAY,GAAE,MAAM,EAAO,GAC1B,cAAc,CAmEhB;AAWD;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,cAAc,EAAE,CAU7D"}
|
package/dist/default.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { getJoyIDCellDep, getJoyIDLockScript } from "@joyid/ckb";
|
|
2
|
+
import { bytes } from "@ckb-lumos/codec";
|
|
3
|
+
import { parseFromInfo } from "@ckb-lumos/common-scripts";
|
|
4
|
+
import { addCellDep } from "@ckb-lumos/common-scripts/lib/helper";
|
|
5
|
+
import { getConfig } from "@ckb-lumos/config-manager";
|
|
6
|
+
import { asserts } from "./utils";
|
|
7
|
+
/**
|
|
8
|
+
* Generates a class for collecting custom script cells.
|
|
9
|
+
* @param {string} codeHash - The code hash of the custom script.
|
|
10
|
+
* @returns {typeof JoyIDCellCollector} The CustomCellCollector class.
|
|
11
|
+
*/
|
|
12
|
+
function generateCollectorClass(codeHash) {
|
|
13
|
+
/**
|
|
14
|
+
* Class representing a collector for custom script cells.
|
|
15
|
+
* @class
|
|
16
|
+
*/
|
|
17
|
+
return class CustomCellCollector {
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instance of CustomCollector.
|
|
20
|
+
* @param {FromInfo} fromInfo - The information about the address to collect cells from.
|
|
21
|
+
* @param {CellProvider} cellProvider - The provider to collect cells from.
|
|
22
|
+
* @param {Object} options - The options for the collector.
|
|
23
|
+
* @param {QueryOptions} [options.queryOptions={}] - The query options for collecting cells.
|
|
24
|
+
* @param {Config} [options.config=getConfig()] - The Lumos configuration.
|
|
25
|
+
* @throws {Error} If cellProvider is not provided or fromInfo is not a string.
|
|
26
|
+
*/
|
|
27
|
+
constructor(fromInfo, cellProvider, { queryOptions = {}, config = getConfig(), }) {
|
|
28
|
+
if (!cellProvider) {
|
|
29
|
+
throw new Error(`cellProvider is required when collecting cells`);
|
|
30
|
+
}
|
|
31
|
+
const { fromScript } = parseFromInfo(fromInfo, { config });
|
|
32
|
+
this.fromScript = fromScript;
|
|
33
|
+
if (!bytes.equal(fromScript.codeHash, codeHash)) {
|
|
34
|
+
this.cellCollector = undefined;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
queryOptions = {
|
|
38
|
+
...queryOptions,
|
|
39
|
+
lock: this.fromScript,
|
|
40
|
+
type: queryOptions.type || "empty",
|
|
41
|
+
data: queryOptions.data || "0x",
|
|
42
|
+
};
|
|
43
|
+
this.cellCollector = cellProvider.collector(queryOptions);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Collects custom cells.
|
|
47
|
+
* @async
|
|
48
|
+
* @generator
|
|
49
|
+
* @yields {Cell} The collected cell.
|
|
50
|
+
*/
|
|
51
|
+
async *collect() {
|
|
52
|
+
if (!this.cellCollector) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
for await (const inputCell of this.cellCollector.collect()) {
|
|
56
|
+
yield inputCell;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Generates custom lock script information.
|
|
63
|
+
* @param {string} codeHash - The code hash of the custom script.
|
|
64
|
+
* @param {CellDep[]} cellDeps - The cell dependencies for the custom script.
|
|
65
|
+
* @returns {LockScriptInfo} The lock script information.
|
|
66
|
+
*/
|
|
67
|
+
export function generateScriptInfo(codeHash, cellDeps, cellDepTypes = []) {
|
|
68
|
+
return {
|
|
69
|
+
codeHash: codeHash,
|
|
70
|
+
hashType: "type",
|
|
71
|
+
lockScriptInfo: {
|
|
72
|
+
CellCollector: generateCollectorClass(codeHash),
|
|
73
|
+
prepareSigningEntries: () => {
|
|
74
|
+
throw new Error("Custom scripts doesn't support prepareSigningEntries.");
|
|
75
|
+
},
|
|
76
|
+
async setupInputCell(txSkeleton, inputCell, _, options = {}) {
|
|
77
|
+
const fromScript = inputCell.cellOutput.lock;
|
|
78
|
+
asserts(bytes.equal(fromScript.codeHash, codeHash), `The input script is not specified script`);
|
|
79
|
+
// add inputCell to txSkeleton
|
|
80
|
+
txSkeleton = txSkeleton.update("inputs", (inputs) => inputs.push(inputCell));
|
|
81
|
+
const output = {
|
|
82
|
+
cellOutput: {
|
|
83
|
+
capacity: inputCell.cellOutput.capacity,
|
|
84
|
+
lock: inputCell.cellOutput.lock,
|
|
85
|
+
type: inputCell.cellOutput.type,
|
|
86
|
+
},
|
|
87
|
+
data: inputCell.data,
|
|
88
|
+
};
|
|
89
|
+
txSkeleton = txSkeleton.update("outputs", (outputs) => outputs.push(output));
|
|
90
|
+
const since = options.since;
|
|
91
|
+
if (since) {
|
|
92
|
+
txSkeleton = txSkeleton.update("inputSinces", (inputSinces) => {
|
|
93
|
+
return inputSinces.set(txSkeleton.get("inputs").size - 1, since);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
cellDeps.forEach((item) => {
|
|
97
|
+
txSkeleton = addCellDep(txSkeleton, item);
|
|
98
|
+
});
|
|
99
|
+
if (txSkeleton.cellProvider != null) {
|
|
100
|
+
await Promise.all(cellDepTypes.map(async (type) => {
|
|
101
|
+
for await (const cell of txSkeleton
|
|
102
|
+
.cellProvider.collector({
|
|
103
|
+
type,
|
|
104
|
+
})
|
|
105
|
+
.collect()) {
|
|
106
|
+
txSkeleton = addCellDep(txSkeleton, {
|
|
107
|
+
depType: "code",
|
|
108
|
+
outPoint: cell.outPoint,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
return txSkeleton;
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const NOSTR_TESTNET_TYPE_HASH = "0x6ae5ee0cb887b2df5a9a18137315b9bdc55be8d52637b2de0624092d5f0c91d5";
|
|
119
|
+
const NOSTR_TESTNET_TYPE = {
|
|
120
|
+
codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
121
|
+
hashType: "type",
|
|
122
|
+
args: "0x8dc56c6f35f0c535e23ded1629b1f20535477a1b43e59f14617d11e32c50e0aa",
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Generates default script information for CCC.
|
|
126
|
+
* @returns {LockScriptInfo[]} An array of lock script information.
|
|
127
|
+
*/
|
|
128
|
+
export function generateDefaultScriptInfos() {
|
|
129
|
+
return [
|
|
130
|
+
generateScriptInfo(getJoyIDLockScript(false).codeHash, [
|
|
131
|
+
getJoyIDCellDep(false),
|
|
132
|
+
]),
|
|
133
|
+
generateScriptInfo(getJoyIDLockScript(true).codeHash, [
|
|
134
|
+
getJoyIDCellDep(true),
|
|
135
|
+
]),
|
|
136
|
+
generateScriptInfo(NOSTR_TESTNET_TYPE_HASH, [], [NOSTR_TESTNET_TYPE]),
|
|
137
|
+
];
|
|
138
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { Config } from "@ckb-lumos/config-manager";
|
|
4
|
-
export declare function generateCollectorClass(codeHash: string): {
|
|
5
|
-
new (fromInfo: FromInfo, cellProvider: CellProvider, { queryOptions, config, }: {
|
|
6
|
-
queryOptions?: QueryOptions;
|
|
7
|
-
config?: Config;
|
|
8
|
-
}): {
|
|
9
|
-
readonly fromScript: Script;
|
|
10
|
-
readonly cellCollector: CellCollector;
|
|
11
|
-
collect(): AsyncGenerator<Cell>;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export declare function generateJoyIDInfo(codeHash: string, cellDeps: CellDep[]): LockScriptInfo;
|
|
15
|
-
export declare function generateDefaultScriptInfos(): LockScriptInfo[];
|
|
1
|
+
export * from "./default";
|
|
2
|
+
export * from "./utils";
|
|
16
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,86 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { addCellDep } from "@ckb-lumos/common-scripts/lib/helper";
|
|
4
|
-
import { getConfig } from "@ckb-lumos/config-manager";
|
|
5
|
-
import { getJoyIDCellDep, getJoyIDLockScript } from "@joyid/ckb";
|
|
6
|
-
export function generateCollectorClass(codeHash) {
|
|
7
|
-
return class JoyIDCellCollector {
|
|
8
|
-
constructor(fromInfo, cellProvider, { queryOptions = {}, config = getConfig(), }) {
|
|
9
|
-
if (!cellProvider) {
|
|
10
|
-
throw new Error(`cellProvider is required when collecting JoyID-related cells`);
|
|
11
|
-
}
|
|
12
|
-
if (typeof fromInfo !== "string") {
|
|
13
|
-
throw new Error(`Only the address FromInfo is supported`);
|
|
14
|
-
}
|
|
15
|
-
const { fromScript } = parseFromInfo(fromInfo, { config });
|
|
16
|
-
this.fromScript = fromScript;
|
|
17
|
-
queryOptions = {
|
|
18
|
-
...queryOptions,
|
|
19
|
-
lock: this.fromScript,
|
|
20
|
-
type: queryOptions.type || "empty",
|
|
21
|
-
data: queryOptions.data || "0x",
|
|
22
|
-
};
|
|
23
|
-
this.cellCollector = cellProvider.collector(queryOptions);
|
|
24
|
-
}
|
|
25
|
-
async *collect() {
|
|
26
|
-
if (!bytes.equal(this.fromScript.codeHash, codeHash)) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
for await (const inputCell of this.cellCollector.collect()) {
|
|
30
|
-
yield inputCell;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export function generateJoyIDInfo(codeHash, cellDeps) {
|
|
36
|
-
return {
|
|
37
|
-
codeHash: codeHash,
|
|
38
|
-
hashType: "type",
|
|
39
|
-
lockScriptInfo: {
|
|
40
|
-
CellCollector: generateCollectorClass(codeHash),
|
|
41
|
-
prepareSigningEntries: () => {
|
|
42
|
-
throw new Error("JoyID doesn't support prepareSigningEntries, please do not mix JoyID locks with other locks in a transaction");
|
|
43
|
-
},
|
|
44
|
-
async setupInputCell(txSkeleton, inputCell, _, options = {}) {
|
|
45
|
-
const fromScript = inputCell.cellOutput.lock;
|
|
46
|
-
asserts(bytes.equal(fromScript.codeHash, codeHash), `The input script is not JoyID script`);
|
|
47
|
-
// add inputCell to txSkeleton
|
|
48
|
-
txSkeleton = txSkeleton.update("inputs", (inputs) => inputs.push(inputCell));
|
|
49
|
-
const output = {
|
|
50
|
-
cellOutput: {
|
|
51
|
-
capacity: inputCell.cellOutput.capacity,
|
|
52
|
-
lock: inputCell.cellOutput.lock,
|
|
53
|
-
type: inputCell.cellOutput.type,
|
|
54
|
-
},
|
|
55
|
-
data: inputCell.data,
|
|
56
|
-
};
|
|
57
|
-
txSkeleton = txSkeleton.update("outputs", (outputs) => outputs.push(output));
|
|
58
|
-
const since = options.since;
|
|
59
|
-
if (since) {
|
|
60
|
-
txSkeleton = txSkeleton.update("inputSinces", (inputSinces) => {
|
|
61
|
-
return inputSinces.set(txSkeleton.get("inputs").size - 1, since);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
cellDeps.forEach((item) => {
|
|
65
|
-
txSkeleton = addCellDep(txSkeleton, item);
|
|
66
|
-
});
|
|
67
|
-
return txSkeleton;
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
export function generateDefaultScriptInfos() {
|
|
73
|
-
return [
|
|
74
|
-
generateJoyIDInfo(getJoyIDLockScript(false).codeHash, [
|
|
75
|
-
getJoyIDCellDep(false),
|
|
76
|
-
]),
|
|
77
|
-
generateJoyIDInfo(getJoyIDLockScript(true).codeHash, [
|
|
78
|
-
getJoyIDCellDep(true),
|
|
79
|
-
]),
|
|
80
|
-
];
|
|
81
|
-
}
|
|
82
|
-
function asserts(condition, message = "Assert failed") {
|
|
83
|
-
if (!condition) {
|
|
84
|
-
throw new Error(message);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
1
|
+
export * from "./default";
|
|
2
|
+
export * from "./utils";
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that a condition is true, throwing an error if it is not.
|
|
3
|
+
* @param {unknown} condition - The condition to assert.
|
|
4
|
+
* @param {string} [message="Assert failed"] - The error message to throw if the condition is false.
|
|
5
|
+
* @throws {Error} If the condition is false.
|
|
6
|
+
*/
|
|
7
|
+
export declare function asserts(condition: unknown, message?: string): asserts condition;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,OAAO,CACrB,SAAS,EAAE,OAAO,EAClB,OAAO,SAAkB,GACxB,OAAO,CAAC,SAAS,CAInB"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that a condition is true, throwing an error if it is not.
|
|
3
|
+
* @param {unknown} condition - The condition to assert.
|
|
4
|
+
* @param {string} [message="Assert failed"] - The error message to throw if the condition is false.
|
|
5
|
+
* @throws {Error} If the condition is false.
|
|
6
|
+
*/
|
|
7
|
+
export function asserts(condition, message = "Assert failed") {
|
|
8
|
+
if (!condition) {
|
|
9
|
+
throw new Error(message);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LockScriptInfo } from "@ckb-lumos/common-scripts";
|
|
2
|
+
import { CellDep, Script } from "@ckb-lumos/base";
|
|
3
|
+
/**
|
|
4
|
+
* Generates custom lock script information.
|
|
5
|
+
* @param {string} codeHash - The code hash of the custom script.
|
|
6
|
+
* @param {CellDep[]} cellDeps - The cell dependencies for the custom script.
|
|
7
|
+
* @returns {LockScriptInfo} The lock script information.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateScriptInfo(codeHash: string, cellDeps: CellDep[], cellDepTypes?: Script[]): LockScriptInfo;
|
|
10
|
+
/**
|
|
11
|
+
* Generates default script information for CCC.
|
|
12
|
+
* @returns {LockScriptInfo[]} An array of lock script information.
|
|
13
|
+
*/
|
|
14
|
+
export declare function generateDefaultScriptInfos(): LockScriptInfo[];
|
|
15
|
+
//# sourceMappingURL=default.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../src/default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EAGL,OAAO,EAGP,MAAM,EACP,MAAM,iBAAiB,CAAC;AA8EzB;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EAAE,EACnB,YAAY,GAAE,MAAM,EAAO,GAC1B,cAAc,CAmEhB;AAWD;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,cAAc,EAAE,CAU7D"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateDefaultScriptInfos = exports.generateScriptInfo = void 0;
|
|
4
|
+
const ckb_1 = require("@joyid/ckb");
|
|
5
|
+
const codec_1 = require("@ckb-lumos/codec");
|
|
6
|
+
const common_scripts_1 = require("@ckb-lumos/common-scripts");
|
|
7
|
+
const helper_1 = require("@ckb-lumos/common-scripts/lib/helper");
|
|
8
|
+
const config_manager_1 = require("@ckb-lumos/config-manager");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
/**
|
|
11
|
+
* Generates a class for collecting custom script cells.
|
|
12
|
+
* @param {string} codeHash - The code hash of the custom script.
|
|
13
|
+
* @returns {typeof JoyIDCellCollector} The CustomCellCollector class.
|
|
14
|
+
*/
|
|
15
|
+
function generateCollectorClass(codeHash) {
|
|
16
|
+
/**
|
|
17
|
+
* Class representing a collector for custom script cells.
|
|
18
|
+
* @class
|
|
19
|
+
*/
|
|
20
|
+
return class CustomCellCollector {
|
|
21
|
+
/**
|
|
22
|
+
* Creates an instance of CustomCollector.
|
|
23
|
+
* @param {FromInfo} fromInfo - The information about the address to collect cells from.
|
|
24
|
+
* @param {CellProvider} cellProvider - The provider to collect cells from.
|
|
25
|
+
* @param {Object} options - The options for the collector.
|
|
26
|
+
* @param {QueryOptions} [options.queryOptions={}] - The query options for collecting cells.
|
|
27
|
+
* @param {Config} [options.config=getConfig()] - The Lumos configuration.
|
|
28
|
+
* @throws {Error} If cellProvider is not provided or fromInfo is not a string.
|
|
29
|
+
*/
|
|
30
|
+
constructor(fromInfo, cellProvider, { queryOptions = {}, config = (0, config_manager_1.getConfig)(), }) {
|
|
31
|
+
if (!cellProvider) {
|
|
32
|
+
throw new Error(`cellProvider is required when collecting cells`);
|
|
33
|
+
}
|
|
34
|
+
const { fromScript } = (0, common_scripts_1.parseFromInfo)(fromInfo, { config });
|
|
35
|
+
this.fromScript = fromScript;
|
|
36
|
+
if (!codec_1.bytes.equal(fromScript.codeHash, codeHash)) {
|
|
37
|
+
this.cellCollector = undefined;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
queryOptions = {
|
|
41
|
+
...queryOptions,
|
|
42
|
+
lock: this.fromScript,
|
|
43
|
+
type: queryOptions.type || "empty",
|
|
44
|
+
data: queryOptions.data || "0x",
|
|
45
|
+
};
|
|
46
|
+
this.cellCollector = cellProvider.collector(queryOptions);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Collects custom cells.
|
|
50
|
+
* @async
|
|
51
|
+
* @generator
|
|
52
|
+
* @yields {Cell} The collected cell.
|
|
53
|
+
*/
|
|
54
|
+
async *collect() {
|
|
55
|
+
if (!this.cellCollector) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
for await (const inputCell of this.cellCollector.collect()) {
|
|
59
|
+
yield inputCell;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Generates custom lock script information.
|
|
66
|
+
* @param {string} codeHash - The code hash of the custom script.
|
|
67
|
+
* @param {CellDep[]} cellDeps - The cell dependencies for the custom script.
|
|
68
|
+
* @returns {LockScriptInfo} The lock script information.
|
|
69
|
+
*/
|
|
70
|
+
function generateScriptInfo(codeHash, cellDeps, cellDepTypes = []) {
|
|
71
|
+
return {
|
|
72
|
+
codeHash: codeHash,
|
|
73
|
+
hashType: "type",
|
|
74
|
+
lockScriptInfo: {
|
|
75
|
+
CellCollector: generateCollectorClass(codeHash),
|
|
76
|
+
prepareSigningEntries: () => {
|
|
77
|
+
throw new Error("Custom scripts doesn't support prepareSigningEntries.");
|
|
78
|
+
},
|
|
79
|
+
async setupInputCell(txSkeleton, inputCell, _, options = {}) {
|
|
80
|
+
const fromScript = inputCell.cellOutput.lock;
|
|
81
|
+
(0, utils_1.asserts)(codec_1.bytes.equal(fromScript.codeHash, codeHash), `The input script is not specified script`);
|
|
82
|
+
// add inputCell to txSkeleton
|
|
83
|
+
txSkeleton = txSkeleton.update("inputs", (inputs) => inputs.push(inputCell));
|
|
84
|
+
const output = {
|
|
85
|
+
cellOutput: {
|
|
86
|
+
capacity: inputCell.cellOutput.capacity,
|
|
87
|
+
lock: inputCell.cellOutput.lock,
|
|
88
|
+
type: inputCell.cellOutput.type,
|
|
89
|
+
},
|
|
90
|
+
data: inputCell.data,
|
|
91
|
+
};
|
|
92
|
+
txSkeleton = txSkeleton.update("outputs", (outputs) => outputs.push(output));
|
|
93
|
+
const since = options.since;
|
|
94
|
+
if (since) {
|
|
95
|
+
txSkeleton = txSkeleton.update("inputSinces", (inputSinces) => {
|
|
96
|
+
return inputSinces.set(txSkeleton.get("inputs").size - 1, since);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
cellDeps.forEach((item) => {
|
|
100
|
+
txSkeleton = (0, helper_1.addCellDep)(txSkeleton, item);
|
|
101
|
+
});
|
|
102
|
+
if (txSkeleton.cellProvider != null) {
|
|
103
|
+
await Promise.all(cellDepTypes.map(async (type) => {
|
|
104
|
+
for await (const cell of txSkeleton
|
|
105
|
+
.cellProvider.collector({
|
|
106
|
+
type,
|
|
107
|
+
})
|
|
108
|
+
.collect()) {
|
|
109
|
+
txSkeleton = (0, helper_1.addCellDep)(txSkeleton, {
|
|
110
|
+
depType: "code",
|
|
111
|
+
outPoint: cell.outPoint,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
return txSkeleton;
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
exports.generateScriptInfo = generateScriptInfo;
|
|
122
|
+
const NOSTR_TESTNET_TYPE_HASH = "0x6ae5ee0cb887b2df5a9a18137315b9bdc55be8d52637b2de0624092d5f0c91d5";
|
|
123
|
+
const NOSTR_TESTNET_TYPE = {
|
|
124
|
+
codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
125
|
+
hashType: "type",
|
|
126
|
+
args: "0x8dc56c6f35f0c535e23ded1629b1f20535477a1b43e59f14617d11e32c50e0aa",
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Generates default script information for CCC.
|
|
130
|
+
* @returns {LockScriptInfo[]} An array of lock script information.
|
|
131
|
+
*/
|
|
132
|
+
function generateDefaultScriptInfos() {
|
|
133
|
+
return [
|
|
134
|
+
generateScriptInfo((0, ckb_1.getJoyIDLockScript)(false).codeHash, [
|
|
135
|
+
(0, ckb_1.getJoyIDCellDep)(false),
|
|
136
|
+
]),
|
|
137
|
+
generateScriptInfo((0, ckb_1.getJoyIDLockScript)(true).codeHash, [
|
|
138
|
+
(0, ckb_1.getJoyIDCellDep)(true),
|
|
139
|
+
]),
|
|
140
|
+
generateScriptInfo(NOSTR_TESTNET_TYPE_HASH, [], [NOSTR_TESTNET_TYPE]),
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
exports.generateDefaultScriptInfos = generateDefaultScriptInfos;
|
package/dist.commonjs/index.d.ts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { Config } from "@ckb-lumos/config-manager";
|
|
4
|
-
export declare function generateCollectorClass(codeHash: string): {
|
|
5
|
-
new (fromInfo: FromInfo, cellProvider: CellProvider, { queryOptions, config, }: {
|
|
6
|
-
queryOptions?: QueryOptions;
|
|
7
|
-
config?: Config;
|
|
8
|
-
}): {
|
|
9
|
-
readonly fromScript: Script;
|
|
10
|
-
readonly cellCollector: CellCollector;
|
|
11
|
-
collect(): AsyncGenerator<Cell>;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export declare function generateJoyIDInfo(codeHash: string, cellDeps: CellDep[]): LockScriptInfo;
|
|
15
|
-
export declare function generateDefaultScriptInfos(): LockScriptInfo[];
|
|
1
|
+
export * from "./default";
|
|
2
|
+
export * from "./utils";
|
|
16
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/dist.commonjs/index.js
CHANGED
|
@@ -1,92 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const config_manager_1 = require("@ckb-lumos/config-manager");
|
|
8
|
-
const ckb_1 = require("@joyid/ckb");
|
|
9
|
-
function generateCollectorClass(codeHash) {
|
|
10
|
-
return class JoyIDCellCollector {
|
|
11
|
-
constructor(fromInfo, cellProvider, { queryOptions = {}, config = (0, config_manager_1.getConfig)(), }) {
|
|
12
|
-
if (!cellProvider) {
|
|
13
|
-
throw new Error(`cellProvider is required when collecting JoyID-related cells`);
|
|
14
|
-
}
|
|
15
|
-
if (typeof fromInfo !== "string") {
|
|
16
|
-
throw new Error(`Only the address FromInfo is supported`);
|
|
17
|
-
}
|
|
18
|
-
const { fromScript } = (0, common_scripts_1.parseFromInfo)(fromInfo, { config });
|
|
19
|
-
this.fromScript = fromScript;
|
|
20
|
-
queryOptions = {
|
|
21
|
-
...queryOptions,
|
|
22
|
-
lock: this.fromScript,
|
|
23
|
-
type: queryOptions.type || "empty",
|
|
24
|
-
data: queryOptions.data || "0x",
|
|
25
|
-
};
|
|
26
|
-
this.cellCollector = cellProvider.collector(queryOptions);
|
|
27
|
-
}
|
|
28
|
-
async *collect() {
|
|
29
|
-
if (!codec_1.bytes.equal(this.fromScript.codeHash, codeHash)) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
for await (const inputCell of this.cellCollector.collect()) {
|
|
33
|
-
yield inputCell;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
exports.generateCollectorClass = generateCollectorClass;
|
|
39
|
-
function generateJoyIDInfo(codeHash, cellDeps) {
|
|
40
|
-
return {
|
|
41
|
-
codeHash: codeHash,
|
|
42
|
-
hashType: "type",
|
|
43
|
-
lockScriptInfo: {
|
|
44
|
-
CellCollector: generateCollectorClass(codeHash),
|
|
45
|
-
prepareSigningEntries: () => {
|
|
46
|
-
throw new Error("JoyID doesn't support prepareSigningEntries, please do not mix JoyID locks with other locks in a transaction");
|
|
47
|
-
},
|
|
48
|
-
async setupInputCell(txSkeleton, inputCell, _, options = {}) {
|
|
49
|
-
const fromScript = inputCell.cellOutput.lock;
|
|
50
|
-
asserts(codec_1.bytes.equal(fromScript.codeHash, codeHash), `The input script is not JoyID script`);
|
|
51
|
-
// add inputCell to txSkeleton
|
|
52
|
-
txSkeleton = txSkeleton.update("inputs", (inputs) => inputs.push(inputCell));
|
|
53
|
-
const output = {
|
|
54
|
-
cellOutput: {
|
|
55
|
-
capacity: inputCell.cellOutput.capacity,
|
|
56
|
-
lock: inputCell.cellOutput.lock,
|
|
57
|
-
type: inputCell.cellOutput.type,
|
|
58
|
-
},
|
|
59
|
-
data: inputCell.data,
|
|
60
|
-
};
|
|
61
|
-
txSkeleton = txSkeleton.update("outputs", (outputs) => outputs.push(output));
|
|
62
|
-
const since = options.since;
|
|
63
|
-
if (since) {
|
|
64
|
-
txSkeleton = txSkeleton.update("inputSinces", (inputSinces) => {
|
|
65
|
-
return inputSinces.set(txSkeleton.get("inputs").size - 1, since);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
cellDeps.forEach((item) => {
|
|
69
|
-
txSkeleton = (0, helper_1.addCellDep)(txSkeleton, item);
|
|
70
|
-
});
|
|
71
|
-
return txSkeleton;
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
exports.generateJoyIDInfo = generateJoyIDInfo;
|
|
77
|
-
function generateDefaultScriptInfos() {
|
|
78
|
-
return [
|
|
79
|
-
generateJoyIDInfo((0, ckb_1.getJoyIDLockScript)(false).codeHash, [
|
|
80
|
-
(0, ckb_1.getJoyIDCellDep)(false),
|
|
81
|
-
]),
|
|
82
|
-
generateJoyIDInfo((0, ckb_1.getJoyIDLockScript)(true).codeHash, [
|
|
83
|
-
(0, ckb_1.getJoyIDCellDep)(true),
|
|
84
|
-
]),
|
|
85
|
-
];
|
|
86
|
-
}
|
|
87
|
-
exports.generateDefaultScriptInfos = generateDefaultScriptInfos;
|
|
88
|
-
function asserts(condition, message = "Assert failed") {
|
|
89
|
-
if (!condition) {
|
|
90
|
-
throw new Error(message);
|
|
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]; } };
|
|
91
7
|
}
|
|
92
|
-
|
|
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("./default"), exports);
|
|
18
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that a condition is true, throwing an error if it is not.
|
|
3
|
+
* @param {unknown} condition - The condition to assert.
|
|
4
|
+
* @param {string} [message="Assert failed"] - The error message to throw if the condition is false.
|
|
5
|
+
* @throws {Error} If the condition is false.
|
|
6
|
+
*/
|
|
7
|
+
export declare function asserts(condition: unknown, message?: string): asserts condition;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,OAAO,CACrB,SAAS,EAAE,OAAO,EAClB,OAAO,SAAkB,GACxB,OAAO,CAAC,SAAS,CAInB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asserts = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Asserts that a condition is true, throwing an error if it is not.
|
|
6
|
+
* @param {unknown} condition - The condition to assert.
|
|
7
|
+
* @param {string} [message="Assert failed"] - The error message to throw if the condition is false.
|
|
8
|
+
* @throws {Error} If the condition is false.
|
|
9
|
+
*/
|
|
10
|
+
function asserts(condition, message = "Assert failed") {
|
|
11
|
+
if (!condition) {
|
|
12
|
+
throw new Error(message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.asserts = asserts;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/lumos-patches",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6-alpha.0",
|
|
4
4
|
"description": "Patches for using Lumos with CCC",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"@ckb-lumos/config-manager": "^0.22.2",
|
|
45
45
|
"@joyid/ckb": "^0.0.11"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "2cbb4f450ed88e773a353a13ad006dbe6208f67f"
|
|
48
48
|
}
|
package/src/default.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { LockScriptInfo } from "@ckb-lumos/common-scripts";
|
|
2
|
+
import { getJoyIDCellDep, getJoyIDLockScript } from "@joyid/ckb";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Cell,
|
|
6
|
+
CellCollector,
|
|
7
|
+
CellDep,
|
|
8
|
+
CellProvider,
|
|
9
|
+
QueryOptions,
|
|
10
|
+
Script,
|
|
11
|
+
} from "@ckb-lumos/base";
|
|
12
|
+
import { bytes } from "@ckb-lumos/codec";
|
|
13
|
+
import { FromInfo, parseFromInfo } from "@ckb-lumos/common-scripts";
|
|
14
|
+
import { addCellDep } from "@ckb-lumos/common-scripts/lib/helper";
|
|
15
|
+
import { Config, getConfig } from "@ckb-lumos/config-manager";
|
|
16
|
+
import { asserts } from "./utils";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generates a class for collecting custom script cells.
|
|
20
|
+
* @param {string} codeHash - The code hash of the custom script.
|
|
21
|
+
* @returns {typeof JoyIDCellCollector} The CustomCellCollector class.
|
|
22
|
+
*/
|
|
23
|
+
function generateCollectorClass(codeHash: string) {
|
|
24
|
+
/**
|
|
25
|
+
* Class representing a collector for custom script cells.
|
|
26
|
+
* @class
|
|
27
|
+
*/
|
|
28
|
+
return class CustomCellCollector {
|
|
29
|
+
readonly fromScript: Script;
|
|
30
|
+
readonly cellCollector: CellCollector | undefined;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates an instance of CustomCollector.
|
|
34
|
+
* @param {FromInfo} fromInfo - The information about the address to collect cells from.
|
|
35
|
+
* @param {CellProvider} cellProvider - The provider to collect cells from.
|
|
36
|
+
* @param {Object} options - The options for the collector.
|
|
37
|
+
* @param {QueryOptions} [options.queryOptions={}] - The query options for collecting cells.
|
|
38
|
+
* @param {Config} [options.config=getConfig()] - The Lumos configuration.
|
|
39
|
+
* @throws {Error} If cellProvider is not provided or fromInfo is not a string.
|
|
40
|
+
*/
|
|
41
|
+
constructor(
|
|
42
|
+
fromInfo: FromInfo,
|
|
43
|
+
cellProvider: CellProvider,
|
|
44
|
+
{
|
|
45
|
+
queryOptions = {},
|
|
46
|
+
config = getConfig(),
|
|
47
|
+
}: { queryOptions?: QueryOptions; config?: Config },
|
|
48
|
+
) {
|
|
49
|
+
if (!cellProvider) {
|
|
50
|
+
throw new Error(`cellProvider is required when collecting cells`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const { fromScript } = parseFromInfo(fromInfo, { config });
|
|
54
|
+
this.fromScript = fromScript;
|
|
55
|
+
|
|
56
|
+
if (!bytes.equal(fromScript.codeHash, codeHash)) {
|
|
57
|
+
this.cellCollector = undefined;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
queryOptions = {
|
|
62
|
+
...queryOptions,
|
|
63
|
+
lock: this.fromScript,
|
|
64
|
+
type: queryOptions.type || "empty",
|
|
65
|
+
data: queryOptions.data || "0x",
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
this.cellCollector = cellProvider.collector(queryOptions);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Collects custom cells.
|
|
73
|
+
* @async
|
|
74
|
+
* @generator
|
|
75
|
+
* @yields {Cell} The collected cell.
|
|
76
|
+
*/
|
|
77
|
+
async *collect(): AsyncGenerator<Cell> {
|
|
78
|
+
if (!this.cellCollector) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
for await (const inputCell of this.cellCollector.collect()) {
|
|
83
|
+
yield inputCell;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Generates custom lock script information.
|
|
91
|
+
* @param {string} codeHash - The code hash of the custom script.
|
|
92
|
+
* @param {CellDep[]} cellDeps - The cell dependencies for the custom script.
|
|
93
|
+
* @returns {LockScriptInfo} The lock script information.
|
|
94
|
+
*/
|
|
95
|
+
export function generateScriptInfo(
|
|
96
|
+
codeHash: string,
|
|
97
|
+
cellDeps: CellDep[],
|
|
98
|
+
cellDepTypes: Script[] = [],
|
|
99
|
+
): LockScriptInfo {
|
|
100
|
+
return {
|
|
101
|
+
codeHash: codeHash,
|
|
102
|
+
hashType: "type",
|
|
103
|
+
lockScriptInfo: {
|
|
104
|
+
CellCollector: generateCollectorClass(codeHash),
|
|
105
|
+
prepareSigningEntries: () => {
|
|
106
|
+
throw new Error(
|
|
107
|
+
"Custom scripts doesn't support prepareSigningEntries.",
|
|
108
|
+
);
|
|
109
|
+
},
|
|
110
|
+
async setupInputCell(txSkeleton, inputCell, _, options = {}) {
|
|
111
|
+
const fromScript = inputCell.cellOutput.lock;
|
|
112
|
+
asserts(
|
|
113
|
+
bytes.equal(fromScript.codeHash, codeHash),
|
|
114
|
+
`The input script is not specified script`,
|
|
115
|
+
);
|
|
116
|
+
// add inputCell to txSkeleton
|
|
117
|
+
txSkeleton = txSkeleton.update("inputs", (inputs) =>
|
|
118
|
+
inputs.push(inputCell),
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const output: Cell = {
|
|
122
|
+
cellOutput: {
|
|
123
|
+
capacity: inputCell.cellOutput.capacity,
|
|
124
|
+
lock: inputCell.cellOutput.lock,
|
|
125
|
+
type: inputCell.cellOutput.type,
|
|
126
|
+
},
|
|
127
|
+
data: inputCell.data,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
txSkeleton = txSkeleton.update("outputs", (outputs) =>
|
|
131
|
+
outputs.push(output),
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const since = options.since;
|
|
135
|
+
if (since) {
|
|
136
|
+
txSkeleton = txSkeleton.update("inputSinces", (inputSinces) => {
|
|
137
|
+
return inputSinces.set(txSkeleton.get("inputs").size - 1, since);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
cellDeps.forEach((item) => {
|
|
142
|
+
txSkeleton = addCellDep(txSkeleton, item);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (txSkeleton.cellProvider != null) {
|
|
146
|
+
await Promise.all(
|
|
147
|
+
cellDepTypes.map(async (type) => {
|
|
148
|
+
for await (const cell of txSkeleton
|
|
149
|
+
.cellProvider!.collector({
|
|
150
|
+
type,
|
|
151
|
+
})
|
|
152
|
+
.collect()) {
|
|
153
|
+
txSkeleton = addCellDep(txSkeleton, {
|
|
154
|
+
depType: "code",
|
|
155
|
+
outPoint: cell.outPoint!,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return txSkeleton;
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const NOSTR_TESTNET_TYPE_HASH =
|
|
169
|
+
"0x6ae5ee0cb887b2df5a9a18137315b9bdc55be8d52637b2de0624092d5f0c91d5";
|
|
170
|
+
const NOSTR_TESTNET_TYPE: Script = {
|
|
171
|
+
codeHash:
|
|
172
|
+
"0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
173
|
+
hashType: "type",
|
|
174
|
+
args: "0x8dc56c6f35f0c535e23ded1629b1f20535477a1b43e59f14617d11e32c50e0aa",
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Generates default script information for CCC.
|
|
179
|
+
* @returns {LockScriptInfo[]} An array of lock script information.
|
|
180
|
+
*/
|
|
181
|
+
export function generateDefaultScriptInfos(): LockScriptInfo[] {
|
|
182
|
+
return [
|
|
183
|
+
generateScriptInfo(getJoyIDLockScript(false).codeHash, [
|
|
184
|
+
getJoyIDCellDep(false),
|
|
185
|
+
]),
|
|
186
|
+
generateScriptInfo(getJoyIDLockScript(true).codeHash, [
|
|
187
|
+
getJoyIDCellDep(true),
|
|
188
|
+
]),
|
|
189
|
+
generateScriptInfo(NOSTR_TESTNET_TYPE_HASH, [], [NOSTR_TESTNET_TYPE]),
|
|
190
|
+
];
|
|
191
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,140 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
CellCollector,
|
|
4
|
-
CellDep,
|
|
5
|
-
CellProvider,
|
|
6
|
-
QueryOptions,
|
|
7
|
-
Script,
|
|
8
|
-
} from "@ckb-lumos/base";
|
|
9
|
-
import { bytes } from "@ckb-lumos/codec";
|
|
10
|
-
import {
|
|
11
|
-
FromInfo,
|
|
12
|
-
LockScriptInfo,
|
|
13
|
-
parseFromInfo,
|
|
14
|
-
} from "@ckb-lumos/common-scripts";
|
|
15
|
-
import { addCellDep } from "@ckb-lumos/common-scripts/lib/helper";
|
|
16
|
-
import { Config, getConfig } from "@ckb-lumos/config-manager";
|
|
17
|
-
import { getJoyIDCellDep, getJoyIDLockScript } from "@joyid/ckb";
|
|
18
|
-
|
|
19
|
-
export function generateCollectorClass(codeHash: string) {
|
|
20
|
-
return class JoyIDCellCollector {
|
|
21
|
-
readonly fromScript: Script;
|
|
22
|
-
readonly cellCollector: CellCollector;
|
|
23
|
-
|
|
24
|
-
constructor(
|
|
25
|
-
fromInfo: FromInfo,
|
|
26
|
-
cellProvider: CellProvider,
|
|
27
|
-
{
|
|
28
|
-
queryOptions = {},
|
|
29
|
-
config = getConfig(),
|
|
30
|
-
}: { queryOptions?: QueryOptions; config?: Config },
|
|
31
|
-
) {
|
|
32
|
-
if (!cellProvider) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`cellProvider is required when collecting JoyID-related cells`,
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (typeof fromInfo !== "string") {
|
|
39
|
-
throw new Error(`Only the address FromInfo is supported`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const { fromScript } = parseFromInfo(fromInfo, { config });
|
|
43
|
-
this.fromScript = fromScript;
|
|
44
|
-
|
|
45
|
-
queryOptions = {
|
|
46
|
-
...queryOptions,
|
|
47
|
-
lock: this.fromScript,
|
|
48
|
-
type: queryOptions.type || "empty",
|
|
49
|
-
data: queryOptions.data || "0x",
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
this.cellCollector = cellProvider.collector(queryOptions);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async *collect(): AsyncGenerator<Cell> {
|
|
56
|
-
if (!bytes.equal(this.fromScript.codeHash, codeHash)) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
for await (const inputCell of this.cellCollector.collect()) {
|
|
61
|
-
yield inputCell;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function generateJoyIDInfo(
|
|
68
|
-
codeHash: string,
|
|
69
|
-
cellDeps: CellDep[],
|
|
70
|
-
): LockScriptInfo {
|
|
71
|
-
return {
|
|
72
|
-
codeHash: codeHash,
|
|
73
|
-
hashType: "type",
|
|
74
|
-
lockScriptInfo: {
|
|
75
|
-
CellCollector: generateCollectorClass(codeHash),
|
|
76
|
-
prepareSigningEntries: () => {
|
|
77
|
-
throw new Error(
|
|
78
|
-
"JoyID doesn't support prepareSigningEntries, please do not mix JoyID locks with other locks in a transaction",
|
|
79
|
-
);
|
|
80
|
-
},
|
|
81
|
-
async setupInputCell(txSkeleton, inputCell, _, options = {}) {
|
|
82
|
-
const fromScript = inputCell.cellOutput.lock;
|
|
83
|
-
asserts(
|
|
84
|
-
bytes.equal(fromScript.codeHash, codeHash),
|
|
85
|
-
`The input script is not JoyID script`,
|
|
86
|
-
);
|
|
87
|
-
// add inputCell to txSkeleton
|
|
88
|
-
txSkeleton = txSkeleton.update("inputs", (inputs) =>
|
|
89
|
-
inputs.push(inputCell),
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const output: Cell = {
|
|
93
|
-
cellOutput: {
|
|
94
|
-
capacity: inputCell.cellOutput.capacity,
|
|
95
|
-
lock: inputCell.cellOutput.lock,
|
|
96
|
-
type: inputCell.cellOutput.type,
|
|
97
|
-
},
|
|
98
|
-
data: inputCell.data,
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
txSkeleton = txSkeleton.update("outputs", (outputs) =>
|
|
102
|
-
outputs.push(output),
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const since = options.since;
|
|
106
|
-
if (since) {
|
|
107
|
-
txSkeleton = txSkeleton.update("inputSinces", (inputSinces) => {
|
|
108
|
-
return inputSinces.set(txSkeleton.get("inputs").size - 1, since);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
cellDeps.forEach((item) => {
|
|
113
|
-
txSkeleton = addCellDep(txSkeleton, item);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
return txSkeleton;
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function generateDefaultScriptInfos(): LockScriptInfo[] {
|
|
123
|
-
return [
|
|
124
|
-
generateJoyIDInfo(getJoyIDLockScript(false).codeHash, [
|
|
125
|
-
getJoyIDCellDep(false),
|
|
126
|
-
]),
|
|
127
|
-
generateJoyIDInfo(getJoyIDLockScript(true).codeHash, [
|
|
128
|
-
getJoyIDCellDep(true),
|
|
129
|
-
]),
|
|
130
|
-
];
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function asserts(
|
|
134
|
-
condition: unknown,
|
|
135
|
-
message = "Assert failed",
|
|
136
|
-
): asserts condition {
|
|
137
|
-
if (!condition) {
|
|
138
|
-
throw new Error(message);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
1
|
+
export * from "./default";
|
|
2
|
+
export * from "./utils";
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that a condition is true, throwing an error if it is not.
|
|
3
|
+
* @param {unknown} condition - The condition to assert.
|
|
4
|
+
* @param {string} [message="Assert failed"] - The error message to throw if the condition is false.
|
|
5
|
+
* @throws {Error} If the condition is false.
|
|
6
|
+
*/
|
|
7
|
+
export function asserts(
|
|
8
|
+
condition: unknown,
|
|
9
|
+
message = "Assert failed",
|
|
10
|
+
): asserts condition {
|
|
11
|
+
if (!condition) {
|
|
12
|
+
throw new Error(message);
|
|
13
|
+
}
|
|
14
|
+
}
|