@ocap/asset 1.17.2 → 1.17.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/lib/index.d.ts +39 -26
- package/lib/index.js +7 -4
- package/package.json +12 -10
package/lib/index.d.ts
CHANGED
@@ -1,5 +1,34 @@
|
|
1
|
+
import type { LiteralUnion, PartialDeep } from 'type-fest';
|
2
|
+
import type { WalletObject } from '@ocap/wallet';
|
3
|
+
import type { AssetFactoryState, CreateAssetTx } from '@ocap/types';
|
1
4
|
declare type $TSFixMe = any;
|
2
|
-
export declare
|
5
|
+
export declare type TPickedFactoryState = PartialDeep<AssetFactoryState.AsObject>;
|
6
|
+
export declare type TIssuer = {
|
7
|
+
name: string;
|
8
|
+
wallet: WalletObject;
|
9
|
+
};
|
10
|
+
export declare type TIssuerInput = {
|
11
|
+
id: string;
|
12
|
+
pk: string;
|
13
|
+
name: string;
|
14
|
+
};
|
15
|
+
export declare type THook = {
|
16
|
+
type: LiteralUnion<'contract' | 'url', string>;
|
17
|
+
name: LiteralUnion<'mint' | 'postMint', string>;
|
18
|
+
hook: string;
|
19
|
+
};
|
20
|
+
export declare type TInputMap = {
|
21
|
+
[key: string]: string;
|
22
|
+
};
|
23
|
+
export declare type TMintResult = {
|
24
|
+
address: string;
|
25
|
+
asset: CreateAssetTx.AsObject;
|
26
|
+
};
|
27
|
+
export declare type TPreMintResult = TMintResult & {
|
28
|
+
variables: TInputMap;
|
29
|
+
issuer: TIssuerInput;
|
30
|
+
};
|
31
|
+
export declare const isValidHook: (hook: THook, quota?: $TSFixMe, throwOnError?: boolean) => boolean;
|
3
32
|
export declare const isValidFactory: (props: $TSFixMe) => boolean;
|
4
33
|
/**
|
5
34
|
* Find credentialSubject path in the object
|
@@ -20,14 +49,11 @@ export declare const findPrerenderKeys: (obj: $TSFixMe, keyword: string) => stri
|
|
20
49
|
* @param {object} params.issuer issuer object
|
21
50
|
*/
|
22
51
|
export declare const mintFromFactory: ({ factory, inputs, owner, issuer, }: {
|
23
|
-
factory:
|
24
|
-
inputs:
|
52
|
+
factory: TPickedFactoryState;
|
53
|
+
inputs: TInputMap;
|
25
54
|
owner: string;
|
26
|
-
issuer:
|
27
|
-
}) =>
|
28
|
-
asset: any;
|
29
|
-
address: string;
|
30
|
-
};
|
55
|
+
issuer: TIssuerInput;
|
56
|
+
}) => TMintResult;
|
31
57
|
/**
|
32
58
|
* Simulate minting from an asset factory, used for client side
|
33
59
|
*
|
@@ -38,23 +64,10 @@ export declare const mintFromFactory: ({ factory, inputs, owner, issuer, }: {
|
|
38
64
|
* @param {object} params.issuer factory issuer wallet and name
|
39
65
|
*/
|
40
66
|
export declare const preMintFromFactory: ({ factory, inputs, owner, issuer, }: {
|
41
|
-
factory?:
|
42
|
-
inputs:
|
67
|
+
factory?: TPickedFactoryState;
|
68
|
+
inputs: TInputMap;
|
43
69
|
owner?: string;
|
44
|
-
issuer?:
|
45
|
-
}) =>
|
46
|
-
|
47
|
-
issuer: {
|
48
|
-
id: any;
|
49
|
-
pk: string;
|
50
|
-
name: any;
|
51
|
-
};
|
52
|
-
variables: any;
|
53
|
-
asset: any;
|
54
|
-
};
|
55
|
-
export declare const formatFactoryState: (state: $TSFixMe) => {
|
56
|
-
address: any;
|
57
|
-
output: any;
|
58
|
-
data: any;
|
59
|
-
};
|
70
|
+
issuer?: TIssuer;
|
71
|
+
}) => TPreMintResult;
|
72
|
+
export declare const formatFactoryState: (state: $TSFixMe) => TPickedFactoryState;
|
60
73
|
export {};
|
package/lib/index.js
CHANGED
@@ -9,6 +9,7 @@ const get_1 = __importDefault(require("lodash/get"));
|
|
9
9
|
const set_1 = __importDefault(require("lodash/set"));
|
10
10
|
const uniq_1 = __importDefault(require("lodash/uniq"));
|
11
11
|
const uniqBy_1 = __importDefault(require("lodash/uniqBy"));
|
12
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
12
13
|
const flat_1 = __importDefault(require("flat"));
|
13
14
|
const mustache_1 = __importDefault(require("mustache"));
|
14
15
|
const is_absolute_url_1 = __importDefault(require("is-absolute-url"));
|
@@ -20,7 +21,6 @@ const mcrypto_1 = require("@ocap/mcrypto");
|
|
20
21
|
const util_1 = require("@ocap/util");
|
21
22
|
const contract_1 = require("@ocap/contract");
|
22
23
|
const debug_1 = __importDefault(require("debug"));
|
23
|
-
const lodash_1 = require("lodash");
|
24
24
|
const debug = (0, debug_1.default)('@ocap/asset');
|
25
25
|
const SUPPORTED_HOOK_NAMES = ['mint', 'postMint'];
|
26
26
|
const SUPPORTED_HOOK_TYPES = ['contract', 'url'];
|
@@ -53,6 +53,8 @@ const isValidHook = (hook, quota, throwOnError = false) => {
|
|
53
53
|
return false;
|
54
54
|
};
|
55
55
|
exports.isValidHook = isValidHook;
|
56
|
+
// FIXME: we should use Joi to validate the schema
|
57
|
+
// @link https://github.com/improbable-eng/ts-protoc-gen
|
56
58
|
const isValidFactory = (props) => {
|
57
59
|
if (!props) {
|
58
60
|
throw new Error('Factory props should not be empty');
|
@@ -66,7 +68,7 @@ const isValidFactory = (props) => {
|
|
66
68
|
throw new Error('Factory settlement prop should only be instant or periodic');
|
67
69
|
}
|
68
70
|
// input.tokens and input.assets should not be empty
|
69
|
-
if (['value', 'tokens', 'assets'].every((x) => (0,
|
71
|
+
if (['value', 'tokens', 'assets'].every((x) => (0, isEmpty_1.default)(props.input[x]))) {
|
70
72
|
throw new Error('Factory input should contain at least one token or asset');
|
71
73
|
}
|
72
74
|
if ((0, uniqBy_1.default)(props.input.tokens, 'address').length !== props.input.tokens.length) {
|
@@ -109,7 +111,7 @@ const isValidFactory = (props) => {
|
|
109
111
|
if (quota.value <= 0 && Object.keys(quota.tokens).every((x) => quota[x] <= 0)) {
|
110
112
|
return true;
|
111
113
|
}
|
112
|
-
if ((0,
|
114
|
+
if ((0, isEmpty_1.default)(props.hooks)) {
|
113
115
|
throw new Error('Factory hooks should not be empty for instant settlement');
|
114
116
|
}
|
115
117
|
const mintHook = props.hooks.find((x) => x.name === 'mint');
|
@@ -255,7 +257,7 @@ const preMintFromFactory = ({ factory, inputs, owner, issuer, }) => {
|
|
255
257
|
};
|
256
258
|
exports.preMintFromFactory = preMintFromFactory;
|
257
259
|
const formatFactoryState = (state) => {
|
258
|
-
const { address, output, data } = state;
|
260
|
+
const { address, output, data, numMinted } = state;
|
259
261
|
const outputX = (0, cloneDeep_1.default)(output);
|
260
262
|
outputX.data.value = JSON.parse(outputX.data.value);
|
261
263
|
outputX.data.type = outputX.data.typeUrl;
|
@@ -263,6 +265,7 @@ const formatFactoryState = (state) => {
|
|
263
265
|
address,
|
264
266
|
output: outputX,
|
265
267
|
data: JSON.parse(data.value),
|
268
|
+
numMinted,
|
266
269
|
};
|
267
270
|
};
|
268
271
|
exports.formatFactoryState = formatFactoryState;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ocap/asset",
|
3
3
|
"description": "Utility to work with asset and factory on ArcBlock blockchain",
|
4
|
-
"version": "1.17.
|
4
|
+
"version": "1.17.5",
|
5
5
|
"author": {
|
6
6
|
"name": "wangshijun",
|
7
7
|
"email": "shijun@arcblock.io",
|
@@ -18,19 +18,21 @@
|
|
18
18
|
"wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"
|
19
19
|
],
|
20
20
|
"dependencies": {
|
21
|
-
"@arcblock/did": "1.17.
|
22
|
-
"@arcblock/did-util": "1.17.
|
23
|
-
"@arcblock/vc": "1.17.
|
24
|
-
"@ocap/contract": "1.17.
|
25
|
-
"@ocap/mcrypto": "1.17.
|
26
|
-
"@ocap/
|
27
|
-
"@ocap/
|
21
|
+
"@arcblock/did": "1.17.5",
|
22
|
+
"@arcblock/did-util": "1.17.5",
|
23
|
+
"@arcblock/vc": "1.17.5",
|
24
|
+
"@ocap/contract": "1.17.5",
|
25
|
+
"@ocap/mcrypto": "1.17.5",
|
26
|
+
"@ocap/types": "1.17.5",
|
27
|
+
"@ocap/util": "1.17.5",
|
28
|
+
"@ocap/wallet": "1.17.5",
|
28
29
|
"debug": "^4.3.3",
|
29
30
|
"flat": "^5.0.2",
|
30
31
|
"is-absolute-url": "^3.0.3",
|
31
32
|
"json-stable-stringify": "^1.0.1",
|
32
33
|
"lodash": "^4.17.21",
|
33
|
-
"mustache": "^4.1.0"
|
34
|
+
"mustache": "^4.1.0",
|
35
|
+
"type-fest": "^2.16.0"
|
34
36
|
},
|
35
37
|
"devDependencies": {
|
36
38
|
"@arcblock/eslint-config-ts": "0.2.2",
|
@@ -71,5 +73,5 @@
|
|
71
73
|
"build": "tsc",
|
72
74
|
"build:watch": "npm run build -- -w"
|
73
75
|
},
|
74
|
-
"gitHead": "
|
76
|
+
"gitHead": "5cacbffd2801318debfe38e5313c63dbdf013eec"
|
75
77
|
}
|