@ocap/asset 1.28.8 → 1.29.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/README.md +0 -1
- package/esm/index.mjs +16 -11
- package/lib/index.cjs +16 -11
- package/package.json +13 -15
package/README.md
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
|
-
[](https://github.com/prettier/prettier)
|
|
4
3
|
[](https://docs.arcblock.io)
|
|
5
4
|
[](https://gitter.im/ArcBlock/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
|
6
5
|
|
package/esm/index.mjs
CHANGED
|
@@ -28,7 +28,7 @@ const isValidNotation = (notation) => [
|
|
|
28
28
|
"ctx",
|
|
29
29
|
"data",
|
|
30
30
|
"input"
|
|
31
|
-
].includes(notation.split(".").shift());
|
|
31
|
+
].includes(notation.split(".").shift() ?? "");
|
|
32
32
|
const isValidHook = (hook, quota, throwOnError = false) => {
|
|
33
33
|
if (SUPPORTED_HOOK_TYPES.includes(hook.type) === false) return false;
|
|
34
34
|
if (SUPPORTED_HOOK_NAMES.includes(hook.name) === false) return false;
|
|
@@ -108,10 +108,10 @@ const mintFromFactory = ({ factory, inputs, owner, issuer }) => {
|
|
|
108
108
|
}, null, 2));
|
|
109
109
|
const asset = JSON.parse(mustache.render(JSON.stringify(output), {
|
|
110
110
|
input: inputs,
|
|
111
|
-
data: data
|
|
111
|
+
data: data?.value || data,
|
|
112
112
|
ctx: {
|
|
113
113
|
factory: factoryAddress,
|
|
114
|
-
id: numMinted + 1,
|
|
114
|
+
id: (numMinted ?? 0) + 1,
|
|
115
115
|
owner,
|
|
116
116
|
issuer
|
|
117
117
|
}
|
|
@@ -137,6 +137,8 @@ const mintFromFactory = ({ factory, inputs, owner, issuer }) => {
|
|
|
137
137
|
*/
|
|
138
138
|
const preMintFromFactory = async ({ factory, inputs, owner, issuer }) => {
|
|
139
139
|
if (Object.keys(inputs).some((x) => typeof inputs[x] !== "string")) throw new Error("Failed to mint asset from factory: input values must be strings");
|
|
140
|
+
if (!factory) throw new Error("Failed to mint asset from factory: factory is required");
|
|
141
|
+
if (!issuer) throw new Error("Failed to mint asset from factory: issuer is required");
|
|
140
142
|
let asset = null;
|
|
141
143
|
const { output, numMinted, address: factoryAddress, data } = factory;
|
|
142
144
|
const { wallet, name } = issuer;
|
|
@@ -160,10 +162,10 @@ const preMintFromFactory = async ({ factory, inputs, owner, issuer }) => {
|
|
|
160
162
|
...inputs,
|
|
161
163
|
...extra
|
|
162
164
|
},
|
|
163
|
-
data: data
|
|
165
|
+
data: data?.value || data,
|
|
164
166
|
ctx: {
|
|
165
167
|
factory: factoryAddress,
|
|
166
|
-
id: numMinted + 1,
|
|
168
|
+
id: (numMinted ?? 0) + 1,
|
|
167
169
|
owner,
|
|
168
170
|
issuer: issuerObject
|
|
169
171
|
}
|
|
@@ -179,21 +181,22 @@ const preMintFromFactory = async ({ factory, inputs, owner, issuer }) => {
|
|
|
179
181
|
const vcRootPath = key.split(".").slice(0, -1).join(".");
|
|
180
182
|
const vcIdPath = vcRootPath.split(".").concat(["id"]).join(".");
|
|
181
183
|
const typeInfo = toTypeInfo(issuerObject.id);
|
|
184
|
+
const pkType = typeInfo.pk;
|
|
182
185
|
const vcType = {
|
|
183
186
|
...typeInfo,
|
|
184
187
|
role: types.RoleType.ROLE_VC
|
|
185
188
|
};
|
|
186
189
|
const vcId = fromPublicKeyHash(wallet.hash(stableStringify(subjectObject)), vcType);
|
|
187
190
|
extra.id = vcId;
|
|
188
|
-
extra.proofType = proofTypes[
|
|
191
|
+
extra.proofType = proofTypes[pkType];
|
|
189
192
|
set(template, vcIdPath, vcId);
|
|
190
|
-
if (!proofTypes[
|
|
193
|
+
if (!proofTypes[pkType]) throw new Error("Unsupported signer type when create verifiable credential");
|
|
191
194
|
let vcObj = render(get(template, vcRootPath));
|
|
192
195
|
vcObj.proof = void 0;
|
|
193
196
|
const vcStr = stableStringify(vcObj);
|
|
194
197
|
const signature = toBase64(await wallet.sign(vcStr));
|
|
195
198
|
vcObj.proof = {
|
|
196
|
-
type: proofTypes[
|
|
199
|
+
type: proofTypes[pkType],
|
|
197
200
|
created: extra.issuanceDate,
|
|
198
201
|
proofPurpose: "assertionMethod",
|
|
199
202
|
jws: signature
|
|
@@ -231,12 +234,14 @@ const preMintFromFactory = async ({ factory, inputs, owner, issuer }) => {
|
|
|
231
234
|
const formatFactoryState = (state) => {
|
|
232
235
|
const { address, output, data, numMinted } = state;
|
|
233
236
|
const outputX = cloneDeep(output);
|
|
234
|
-
|
|
235
|
-
|
|
237
|
+
const outputData = outputX.data;
|
|
238
|
+
outputData.value = JSON.parse(outputData.value);
|
|
239
|
+
outputData.type = outputData.typeUrl;
|
|
240
|
+
const stateData = data;
|
|
236
241
|
return {
|
|
237
242
|
address,
|
|
238
243
|
output: outputX,
|
|
239
|
-
data:
|
|
244
|
+
data: stateData?.value ? JSON.parse(stateData.value) : {},
|
|
240
245
|
numMinted
|
|
241
246
|
};
|
|
242
247
|
};
|
package/lib/index.cjs
CHANGED
|
@@ -39,7 +39,7 @@ const isValidNotation = (notation) => [
|
|
|
39
39
|
"ctx",
|
|
40
40
|
"data",
|
|
41
41
|
"input"
|
|
42
|
-
].includes(notation.split(".").shift());
|
|
42
|
+
].includes(notation.split(".").shift() ?? "");
|
|
43
43
|
const isValidHook = (hook, quota, throwOnError = false) => {
|
|
44
44
|
if (SUPPORTED_HOOK_TYPES.includes(hook.type) === false) return false;
|
|
45
45
|
if (SUPPORTED_HOOK_NAMES.includes(hook.name) === false) return false;
|
|
@@ -119,10 +119,10 @@ const mintFromFactory = ({ factory, inputs, owner, issuer }) => {
|
|
|
119
119
|
}, null, 2));
|
|
120
120
|
const asset = JSON.parse(mustache.default.render(JSON.stringify(output), {
|
|
121
121
|
input: inputs,
|
|
122
|
-
data: data
|
|
122
|
+
data: data?.value || data,
|
|
123
123
|
ctx: {
|
|
124
124
|
factory: factoryAddress,
|
|
125
|
-
id: numMinted + 1,
|
|
125
|
+
id: (numMinted ?? 0) + 1,
|
|
126
126
|
owner,
|
|
127
127
|
issuer
|
|
128
128
|
}
|
|
@@ -148,6 +148,8 @@ const mintFromFactory = ({ factory, inputs, owner, issuer }) => {
|
|
|
148
148
|
*/
|
|
149
149
|
const preMintFromFactory = async ({ factory, inputs, owner, issuer }) => {
|
|
150
150
|
if (Object.keys(inputs).some((x) => typeof inputs[x] !== "string")) throw new Error("Failed to mint asset from factory: input values must be strings");
|
|
151
|
+
if (!factory) throw new Error("Failed to mint asset from factory: factory is required");
|
|
152
|
+
if (!issuer) throw new Error("Failed to mint asset from factory: issuer is required");
|
|
151
153
|
let asset = null;
|
|
152
154
|
const { output, numMinted, address: factoryAddress, data } = factory;
|
|
153
155
|
const { wallet, name } = issuer;
|
|
@@ -171,10 +173,10 @@ const preMintFromFactory = async ({ factory, inputs, owner, issuer }) => {
|
|
|
171
173
|
...inputs,
|
|
172
174
|
...extra
|
|
173
175
|
},
|
|
174
|
-
data: data
|
|
176
|
+
data: data?.value || data,
|
|
175
177
|
ctx: {
|
|
176
178
|
factory: factoryAddress,
|
|
177
|
-
id: numMinted + 1,
|
|
179
|
+
id: (numMinted ?? 0) + 1,
|
|
178
180
|
owner,
|
|
179
181
|
issuer: issuerObject
|
|
180
182
|
}
|
|
@@ -190,21 +192,22 @@ const preMintFromFactory = async ({ factory, inputs, owner, issuer }) => {
|
|
|
190
192
|
const vcRootPath = key.split(".").slice(0, -1).join(".");
|
|
191
193
|
const vcIdPath = vcRootPath.split(".").concat(["id"]).join(".");
|
|
192
194
|
const typeInfo = (0, _arcblock_did.toTypeInfo)(issuerObject.id);
|
|
195
|
+
const pkType = typeInfo.pk;
|
|
193
196
|
const vcType = {
|
|
194
197
|
...typeInfo,
|
|
195
198
|
role: _ocap_mcrypto.types.RoleType.ROLE_VC
|
|
196
199
|
};
|
|
197
200
|
const vcId = (0, _arcblock_did.fromPublicKeyHash)(wallet.hash((0, _arcblock_vc.stableStringify)(subjectObject)), vcType);
|
|
198
201
|
extra.id = vcId;
|
|
199
|
-
extra.proofType = _arcblock_vc.proofTypes[
|
|
202
|
+
extra.proofType = _arcblock_vc.proofTypes[pkType];
|
|
200
203
|
(0, lodash_set.default)(template, vcIdPath, vcId);
|
|
201
|
-
if (!_arcblock_vc.proofTypes[
|
|
204
|
+
if (!_arcblock_vc.proofTypes[pkType]) throw new Error("Unsupported signer type when create verifiable credential");
|
|
202
205
|
let vcObj = render((0, lodash_get.default)(template, vcRootPath));
|
|
203
206
|
vcObj.proof = void 0;
|
|
204
207
|
const vcStr = (0, _arcblock_vc.stableStringify)(vcObj);
|
|
205
208
|
const signature = (0, _ocap_util.toBase64)(await wallet.sign(vcStr));
|
|
206
209
|
vcObj.proof = {
|
|
207
|
-
type: _arcblock_vc.proofTypes[
|
|
210
|
+
type: _arcblock_vc.proofTypes[pkType],
|
|
208
211
|
created: extra.issuanceDate,
|
|
209
212
|
proofPurpose: "assertionMethod",
|
|
210
213
|
jws: signature
|
|
@@ -242,12 +245,14 @@ const preMintFromFactory = async ({ factory, inputs, owner, issuer }) => {
|
|
|
242
245
|
const formatFactoryState = (state) => {
|
|
243
246
|
const { address, output, data, numMinted } = state;
|
|
244
247
|
const outputX = (0, lodash_cloneDeep.default)(output);
|
|
245
|
-
|
|
246
|
-
|
|
248
|
+
const outputData = outputX.data;
|
|
249
|
+
outputData.value = JSON.parse(outputData.value);
|
|
250
|
+
outputData.type = outputData.typeUrl;
|
|
251
|
+
const stateData = data;
|
|
247
252
|
return {
|
|
248
253
|
address,
|
|
249
254
|
output: outputX,
|
|
250
|
-
data:
|
|
255
|
+
data: stateData?.value ? JSON.parse(stateData.value) : {},
|
|
251
256
|
numMinted
|
|
252
257
|
};
|
|
253
258
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@ocap/asset",
|
|
3
3
|
"description": "Utility to work with asset and factory on ArcBlock blockchain",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.29.0",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "wangshijun",
|
|
8
8
|
"email": "shijun@arcblock.io",
|
|
@@ -19,30 +19,28 @@
|
|
|
19
19
|
"wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@arcblock/did": "1.
|
|
23
|
-
"@arcblock/did-util": "1.
|
|
24
|
-
"@arcblock/validator": "1.
|
|
25
|
-
"@arcblock/vc": "1.
|
|
26
|
-
"@ocap/contract": "1.
|
|
27
|
-
"@ocap/mcrypto": "1.
|
|
28
|
-
"@ocap/types": "1.
|
|
29
|
-
"@ocap/util": "1.
|
|
30
|
-
"@ocap/wallet": "1.
|
|
31
|
-
"debug": "^4.3
|
|
22
|
+
"@arcblock/did": "1.29.0",
|
|
23
|
+
"@arcblock/did-util": "1.29.0",
|
|
24
|
+
"@arcblock/validator": "1.29.0",
|
|
25
|
+
"@arcblock/vc": "1.29.0",
|
|
26
|
+
"@ocap/contract": "1.29.0",
|
|
27
|
+
"@ocap/mcrypto": "1.29.0",
|
|
28
|
+
"@ocap/types": "1.29.0",
|
|
29
|
+
"@ocap/util": "1.29.0",
|
|
30
|
+
"@ocap/wallet": "1.29.0",
|
|
31
|
+
"debug": "^4.4.3",
|
|
32
32
|
"flat": "^5.0.2",
|
|
33
33
|
"is-absolute-url": "^3.0.3",
|
|
34
34
|
"json-stable-stringify": "^1.0.1",
|
|
35
|
-
"lodash": "^4.17.
|
|
35
|
+
"lodash": "^4.17.23",
|
|
36
36
|
"mustache": "^4.2.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/flat": "^5.0.5",
|
|
40
40
|
"@types/mustache": "^4.2.5",
|
|
41
41
|
"@types/node": "^22.7.5",
|
|
42
|
-
"prettier": "^3.3.2",
|
|
43
42
|
"tsdown": "^0.18.4",
|
|
44
|
-
"type-fest": "^3.1.0"
|
|
45
|
-
"typescript": "^5.6.2"
|
|
43
|
+
"type-fest": "^3.1.0"
|
|
46
44
|
},
|
|
47
45
|
"homepage": "https://github.com/ArcBlock/blockchain/tree/master/core/asset",
|
|
48
46
|
"keywords": [
|