@kaspacom/kcc20-tx-builder 0.1.0 → 0.2.5
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/artifacts.d.ts +2 -0
- package/dist/artifacts.d.ts.map +1 -1
- package/dist/artifacts.js +3 -1
- package/dist/artifacts.js.map +1 -1
- package/dist/builder.d.ts +0 -2
- package/dist/builder.d.ts.map +1 -1
- package/dist/cjs/artifacts.d.ts +2 -0
- package/dist/cjs/artifacts.js +4 -2
- package/dist/cjs/artifacts.js.map +1 -1
- package/dist/cjs/builder.d.ts +0 -2
- package/dist/cjs/deploy-receipt.d.ts +45 -0
- package/dist/cjs/deploy-receipt.js +122 -0
- package/dist/cjs/deploy-receipt.js.map +1 -0
- package/dist/cjs/engine.js +336 -226
- package/dist/cjs/engine.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/protocol.d.ts +1 -0
- package/dist/cjs/protocol.js +15 -0
- package/dist/cjs/protocol.js.map +1 -1
- package/dist/deploy-receipt.d.ts +46 -0
- package/dist/deploy-receipt.d.ts.map +1 -0
- package/dist/deploy-receipt.js +119 -0
- package/dist/deploy-receipt.js.map +1 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +337 -227
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/protocol.d.ts +1 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +14 -0
- package/dist/protocol.js.map +1 -1
- package/package.json +1 -1
- package/src/artifacts.ts +5 -1
- package/src/builder.ts +0 -3
- package/src/deploy-receipt.ts +200 -0
- package/src/engine.ts +429 -296
- package/src/index.ts +1 -0
- package/src/protocol.ts +21 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./action-source-resolver.js";
|
|
|
3
3
|
export * from "./abi.js";
|
|
4
4
|
export * from "./builder.js";
|
|
5
5
|
export * from "./deploy-operation.js";
|
|
6
|
+
export * from "./deploy-receipt.js";
|
|
6
7
|
export * from "./errors.js";
|
|
7
8
|
export * from "./encoding.js";
|
|
8
9
|
export * from "./engine.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./action-source-resolver.js";
|
|
|
3
3
|
export * from "./abi.js";
|
|
4
4
|
export * from "./builder.js";
|
|
5
5
|
export * from "./deploy-operation.js";
|
|
6
|
+
export * from "./deploy-receipt.js";
|
|
6
7
|
export * from "./errors.js";
|
|
7
8
|
export * from "./encoding.js";
|
|
8
9
|
export * from "./engine.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,2B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cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC"}
|
package/dist/protocol.d.ts
CHANGED
|
@@ -19,4 +19,5 @@ export declare const KCC20_DEFAULT_PROTOCOL_FEE_BPS = 200n;
|
|
|
19
19
|
export declare const KCC20_DEFAULT_PRICE_SCALE: bigint;
|
|
20
20
|
export declare const KCC20_PLATFORM_PROTOCOL_FEE_RECIPIENT: "ce2100e68197c8e695bd781d07e2bd5de7ed77f5a97668884190531bdc632c01";
|
|
21
21
|
export declare const KCC20_ORDERBOOK_PROTOCOL_FEE_RECIPIENT: "ce2100e68197c8e695bd781d07e2bd5de7ed77f5a97668884190531bdc632c01";
|
|
22
|
+
export declare function splitKcc20MintSupply(remainingSupply: bigint, laneCount: bigint): bigint[];
|
|
22
23
|
//# sourceMappingURL=protocol.d.ts.map
|
package/dist/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,EAC/B,0CAAmD,CAAC;AACtD,eAAO,MAAM,SAAS,EACpB,kEAA2E,CAAC;AAC9E,eAAO,MAAM,cAAc,aAAe,CAAC;AAC3C,eAAO,MAAM,0BAA0B,YAAc,CAAC;AACtD,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,oCAAoC,YAAc,CAAC;AAChE,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAC9C,eAAO,MAAM,oCAAoC,UAAW,CAAC;AAC7D,eAAO,MAAM,0CAA0C,YAAY,CAAC;AACpE,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAC9C,eAAO,MAAM,kCAAkC,IAAI,CAAC;AACpD,eAAO,MAAM,2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C,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,GAChB,MAAM,EAAE,CAgBV"}
|
package/dist/protocol.js
CHANGED
|
@@ -19,4 +19,18 @@ export const KCC20_DEFAULT_PROTOCOL_FEE_BPS = DEFAULT_KCC20_FEE_BPS;
|
|
|
19
19
|
export const KCC20_DEFAULT_PRICE_SCALE = DEFAULT_KCC20_PRICE_SCALE;
|
|
20
20
|
export const KCC20_PLATFORM_PROTOCOL_FEE_RECIPIENT = "ce2100e68197c8e695bd781d07e2bd5de7ed77f5a97668884190531bdc632c01";
|
|
21
21
|
export const KCC20_ORDERBOOK_PROTOCOL_FEE_RECIPIENT = KCC20_PLATFORM_PROTOCOL_FEE_RECIPIENT;
|
|
22
|
+
export function splitKcc20MintSupply(remainingSupply, laneCount) {
|
|
23
|
+
if (remainingSupply <= 0n) {
|
|
24
|
+
throw new Error("remaining mint supply must be greater than zero");
|
|
25
|
+
}
|
|
26
|
+
if (laneCount < 1n || laneCount > 10n) {
|
|
27
|
+
throw new Error("mint lane count must be between 1 and 10");
|
|
28
|
+
}
|
|
29
|
+
if (remainingSupply < laneCount) {
|
|
30
|
+
throw new Error("remaining mint supply must cover every mint lane");
|
|
31
|
+
}
|
|
32
|
+
const base = remainingSupply / laneCount;
|
|
33
|
+
const remainder = remainingSupply % laneCount;
|
|
34
|
+
return Array.from({ length: Number(laneCount) }, (_, index) => base + (BigInt(index) < remainder ? 1n : 0n));
|
|
35
|
+
}
|
|
22
36
|
//# sourceMappingURL=protocol.js.map
|
package/dist/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAC/B,0CAAmD,CAAC;AACtD,MAAM,CAAC,MAAM,SAAS,GACpB,kEAA2E,CAAC;AAC9E,MAAM,CAAC,MAAM,cAAc,GAAG,UAAY,C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,IAAI,eAAe,GAAG,SAAS,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,MAAM,IAAI,GAAG,eAAe,GAAG,SAAS,CAAC;IACzC,MAAM,SAAS,GAAG,eAAe,GAAG,SAAS,CAAC;IAC9C,OAAO,KAAK,CAAC,IAAI,CACf,EAAE,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,EAC7B,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAC3D,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
package/src/artifacts.ts
CHANGED
|
@@ -2,8 +2,12 @@ import { Kcc20BuilderError } from "./errors.js";
|
|
|
2
2
|
import type { ArtifactDescriptor, BuildContext } from "./models.js";
|
|
3
3
|
import { sha256 } from "@noble/hashes/sha256";
|
|
4
4
|
|
|
5
|
+
/** The only native KCC20 artifact used to build new transactions. */
|
|
6
|
+
export const KCC20_CURRENT_NATIVE_ARTIFACT_KEY =
|
|
7
|
+
"KCC20.placeholder.json" as const;
|
|
8
|
+
|
|
5
9
|
export const KCC20_ARTIFACT_SCRIPT_SHA256 = Object.freeze({
|
|
6
|
-
|
|
10
|
+
[KCC20_CURRENT_NATIVE_ARTIFACT_KEY]:
|
|
7
11
|
"4633b082f26adbf14600b767d6e2146e36ce67d63d8202c0281857922c05ac41",
|
|
8
12
|
"KCC20FeeTicket.placeholder.json":
|
|
9
13
|
"ed81365466ee4c44db1210b3360783af8145f74e49e847848195e09c71ad6930",
|
package/src/builder.ts
CHANGED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
export interface Kcc20DeployReceiptOutput {
|
|
2
|
+
index: number;
|
|
3
|
+
revealScriptHex: string;
|
|
4
|
+
extensionCommitment: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface Kcc20DeployMinterReceiptOutput extends Kcc20DeployReceiptOutput {
|
|
8
|
+
remainingSupply: string | bigint;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Kcc20DeployIntentOutput {
|
|
12
|
+
role: "fixed-supply-token" | "mint-authority" | "premint-holder";
|
|
13
|
+
index: number;
|
|
14
|
+
shard?: number;
|
|
15
|
+
mintLaneIndex?: number;
|
|
16
|
+
covenantId: string;
|
|
17
|
+
revealScriptHex: string;
|
|
18
|
+
owner: string;
|
|
19
|
+
ownerScheme: number;
|
|
20
|
+
borrowScheme: number;
|
|
21
|
+
borrowGuard: string;
|
|
22
|
+
extensionCommitment: string;
|
|
23
|
+
tokenAmount: string;
|
|
24
|
+
remainingSupply?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface BuildKcc20DeployIntentOutputsInput {
|
|
28
|
+
mintPolicy: number;
|
|
29
|
+
covenantId: string;
|
|
30
|
+
creator: string;
|
|
31
|
+
premintRecipient: string;
|
|
32
|
+
premintOwnerScheme: number;
|
|
33
|
+
maxSupply: string | bigint;
|
|
34
|
+
premintSupply: string | bigint;
|
|
35
|
+
borrowGuard: string;
|
|
36
|
+
fixedOutput?: Kcc20DeployReceiptOutput | null;
|
|
37
|
+
minterOutputs?: readonly Kcc20DeployMinterReceiptOutput[];
|
|
38
|
+
premintOutput?: Kcc20DeployReceiptOutput | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Describes the covenant outputs created by a KCC20 deploy transaction.
|
|
43
|
+
*
|
|
44
|
+
* Fixed-supply deployments create one holder output. Mintable deployments
|
|
45
|
+
* create one or more mint-authority lanes and may append a premint holder.
|
|
46
|
+
* Keeping this mapping next to the transaction builder prevents receipts from
|
|
47
|
+
* claiming that output zero owns supply it does not actually contain.
|
|
48
|
+
*/
|
|
49
|
+
export function buildKcc20DeployIntentOutputs(
|
|
50
|
+
input: BuildKcc20DeployIntentOutputsInput,
|
|
51
|
+
): Kcc20DeployIntentOutput[] {
|
|
52
|
+
const mintPolicy = requireMintPolicy(input.mintPolicy);
|
|
53
|
+
const maxSupply = unsignedInteger(input.maxSupply, "maxSupply");
|
|
54
|
+
const premintSupply = unsignedInteger(input.premintSupply, "premintSupply");
|
|
55
|
+
const minterOutputs = [...(input.minterOutputs ?? [])];
|
|
56
|
+
|
|
57
|
+
if (maxSupply === 0n) {
|
|
58
|
+
throw new Error("KCC20 deploy receipt maxSupply must be positive");
|
|
59
|
+
}
|
|
60
|
+
if (premintSupply > maxSupply) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
"KCC20 deploy receipt premintSupply cannot exceed maxSupply",
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (mintPolicy === 0) {
|
|
67
|
+
if (!input.fixedOutput) {
|
|
68
|
+
throw new Error("fixed KCC20 deploy receipt output is required");
|
|
69
|
+
}
|
|
70
|
+
if (minterOutputs.length || input.premintOutput) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"fixed KCC20 deploy receipt cannot contain mint-authority or premint outputs",
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (premintSupply !== maxSupply) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
"fixed KCC20 deploy receipt must assign the full supply to its holder",
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
assertUniqueOutputIndexes([input.fixedOutput]);
|
|
81
|
+
return [
|
|
82
|
+
holderIntent("fixed-supply-token", input.fixedOutput, input, maxSupply),
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!minterOutputs.length) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
"mintable KCC20 deploy receipt requires at least one mint-authority lane",
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
if (input.fixedOutput) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
"mintable KCC20 deploy receipt cannot contain a fixed-supply output",
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
const hasPremint = premintSupply > 0n;
|
|
97
|
+
if (hasPremint !== Boolean(input.premintOutput)) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
"mintable KCC20 deploy receipt premint output does not match premintSupply",
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const laneSupplies = minterOutputs.map((output, laneIndex) => {
|
|
104
|
+
const supply = unsignedInteger(
|
|
105
|
+
output.remainingSupply,
|
|
106
|
+
`mint lane ${laneIndex} remainingSupply`,
|
|
107
|
+
);
|
|
108
|
+
if (supply === 0n) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`mint lane ${laneIndex} remainingSupply must be positive`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
return supply;
|
|
114
|
+
});
|
|
115
|
+
const laneSupply = laneSupplies.reduce((sum, supply) => sum + supply, 0n);
|
|
116
|
+
if (laneSupply + premintSupply !== maxSupply) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
"mintable KCC20 deploy receipt lane and premint supply must equal maxSupply",
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
assertUniqueOutputIndexes([
|
|
122
|
+
...minterOutputs,
|
|
123
|
+
...(input.premintOutput ? [input.premintOutput] : []),
|
|
124
|
+
]);
|
|
125
|
+
|
|
126
|
+
const intents: Kcc20DeployIntentOutput[] = minterOutputs.map(
|
|
127
|
+
(output, laneIndex) => ({
|
|
128
|
+
role: "mint-authority",
|
|
129
|
+
shard: laneIndex,
|
|
130
|
+
mintLaneIndex: laneIndex,
|
|
131
|
+
index: output.index,
|
|
132
|
+
covenantId: input.covenantId,
|
|
133
|
+
revealScriptHex: output.revealScriptHex,
|
|
134
|
+
owner: input.creator,
|
|
135
|
+
ownerScheme: 0,
|
|
136
|
+
borrowScheme: 0,
|
|
137
|
+
borrowGuard: input.borrowGuard,
|
|
138
|
+
extensionCommitment: output.extensionCommitment,
|
|
139
|
+
tokenAmount: "0",
|
|
140
|
+
remainingSupply: laneSupplies[laneIndex].toString(),
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
if (input.premintOutput) {
|
|
145
|
+
intents.push(
|
|
146
|
+
holderIntent("premint-holder", input.premintOutput, input, premintSupply),
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return intents;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function holderIntent(
|
|
153
|
+
role: "fixed-supply-token" | "premint-holder",
|
|
154
|
+
output: Kcc20DeployReceiptOutput,
|
|
155
|
+
input: BuildKcc20DeployIntentOutputsInput,
|
|
156
|
+
tokenAmount: bigint,
|
|
157
|
+
): Kcc20DeployIntentOutput {
|
|
158
|
+
return {
|
|
159
|
+
role,
|
|
160
|
+
index: output.index,
|
|
161
|
+
covenantId: input.covenantId,
|
|
162
|
+
revealScriptHex: output.revealScriptHex,
|
|
163
|
+
owner: input.premintRecipient,
|
|
164
|
+
ownerScheme: input.premintOwnerScheme,
|
|
165
|
+
borrowScheme: 0,
|
|
166
|
+
borrowGuard: input.borrowGuard,
|
|
167
|
+
extensionCommitment: output.extensionCommitment,
|
|
168
|
+
tokenAmount: tokenAmount.toString(),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function requireMintPolicy(value: number): number {
|
|
173
|
+
if (!Number.isInteger(value) || value < 0 || value > 2) {
|
|
174
|
+
throw new Error("KCC20 deploy receipt mintPolicy must be 0, 1, or 2");
|
|
175
|
+
}
|
|
176
|
+
return value;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function assertUniqueOutputIndexes(
|
|
180
|
+
outputs: readonly Kcc20DeployReceiptOutput[],
|
|
181
|
+
): void {
|
|
182
|
+
const indexes = new Set<number>();
|
|
183
|
+
for (const output of outputs) {
|
|
184
|
+
if (!Number.isInteger(output.index) || output.index < 0) {
|
|
185
|
+
throw new Error("KCC20 deploy receipt output index must be nonnegative");
|
|
186
|
+
}
|
|
187
|
+
if (indexes.has(output.index)) {
|
|
188
|
+
throw new Error("KCC20 deploy receipt output indexes must be unique");
|
|
189
|
+
}
|
|
190
|
+
indexes.add(output.index);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function unsignedInteger(value: string | bigint, label: string): bigint {
|
|
195
|
+
const raw = String(value);
|
|
196
|
+
if (!/^(0|[1-9][0-9]*)$/.test(raw)) {
|
|
197
|
+
throw new Error(`${label} must be an unsigned integer`);
|
|
198
|
+
}
|
|
199
|
+
return BigInt(raw);
|
|
200
|
+
}
|