@blocklet/meta 1.8.34 → 1.8.36

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.
Files changed (58) hide show
  1. package/lib/channel.d.ts +27 -0
  2. package/lib/channel.js +32 -32
  3. package/lib/constants.d.ts +2 -0
  4. package/lib/constants.js +6 -3
  5. package/lib/did.d.ts +10 -0
  6. package/lib/did.js +18 -24
  7. package/lib/engine.d.ts +7 -0
  8. package/lib/engine.js +21 -25
  9. package/lib/entry.d.ts +3 -0
  10. package/lib/entry.js +51 -64
  11. package/lib/extension.d.ts +10 -0
  12. package/lib/extension.js +78 -77
  13. package/lib/file.d.ts +21 -0
  14. package/lib/file.js +44 -39
  15. package/lib/fix.d.ts +33 -0
  16. package/lib/fix.js +218 -208
  17. package/lib/get-component-process-id.d.ts +5 -0
  18. package/lib/get-component-process-id.js +13 -14
  19. package/lib/has-reserved-key.d.ts +3 -0
  20. package/lib/has-reserved-key.js +10 -9
  21. package/lib/index.d.ts +82 -0
  22. package/lib/index.js +51 -34
  23. package/lib/info.d.ts +13 -0
  24. package/lib/info.js +58 -60
  25. package/lib/name.d.ts +5 -0
  26. package/lib/name.js +14 -7
  27. package/lib/nft-templates.d.ts +86 -0
  28. package/lib/nft-templates.js +47 -42
  29. package/lib/parse-navigation.d.ts +3 -0
  30. package/lib/parse-navigation.js +167 -228
  31. package/lib/parse.d.ts +22 -0
  32. package/lib/parse.js +71 -82
  33. package/lib/payment/index.d.ts +254 -0
  34. package/lib/payment/index.js +13 -6
  35. package/lib/payment/v1.d.ts +185 -0
  36. package/lib/payment/v1.js +80 -81
  37. package/lib/payment/v2.d.ts +242 -0
  38. package/lib/payment/v2.js +453 -531
  39. package/lib/schema.d.ts +50 -0
  40. package/lib/schema.js +405 -402
  41. package/lib/service-configs/auth.json +61 -61
  42. package/lib/service.d.ts +26 -0
  43. package/lib/service.js +69 -85
  44. package/lib/types/index.d.ts +1 -0
  45. package/lib/types/index.js +18 -0
  46. package/lib/types/schema.d.ts +241 -0
  47. package/lib/types/schema.js +3 -0
  48. package/lib/util-meta.d.ts +42 -0
  49. package/lib/util-meta.js +138 -158
  50. package/lib/util.d.ts +185 -0
  51. package/lib/util.js +359 -414
  52. package/lib/validate.d.ts +10 -0
  53. package/lib/validate.js +28 -34
  54. package/lib/verify-multi-sig.d.ts +3 -0
  55. package/lib/verify-multi-sig.js +94 -101
  56. package/lib/wallet.d.ts +9 -0
  57. package/lib/wallet.js +17 -27
  58. package/package.json +40 -18
@@ -0,0 +1,254 @@
1
+ import v2 from './v2';
2
+ export declare const createNftFactoryItx: ({ meta, tokens, shares, issuers, serviceUrl, }: {
3
+ meta: import("../types").TBlockletMeta;
4
+ tokens: Pick<import("@abtnode/client").BlockletPaymentPrice, "address" | "value">[];
5
+ shares: {
6
+ value: number;
7
+ address: string;
8
+ }[];
9
+ issuers: string[];
10
+ serviceUrl: string;
11
+ }) => {
12
+ name: string;
13
+ description: string;
14
+ settlement: string;
15
+ limit: number;
16
+ trustedIssuers: string[];
17
+ input: {
18
+ tokens: Pick<import("@abtnode/client").BlockletPaymentPrice, "address" | "value">[];
19
+ assets: any[];
20
+ variables: any[];
21
+ };
22
+ output: {
23
+ issuer: string;
24
+ parent: string;
25
+ moniker: string;
26
+ readonly: boolean;
27
+ transferrable: boolean;
28
+ data: {
29
+ type: string;
30
+ value: {
31
+ '@context': string;
32
+ id: string;
33
+ tag: string[];
34
+ type: string[];
35
+ issuer: {
36
+ id: string;
37
+ pk: string;
38
+ name: string;
39
+ };
40
+ issuanceDate: string;
41
+ credentialSubject: {
42
+ id: string;
43
+ sn: string;
44
+ purchased: {
45
+ blocklet: {
46
+ id: string;
47
+ url: string;
48
+ name: string;
49
+ };
50
+ };
51
+ display: {
52
+ type: string;
53
+ content: string;
54
+ };
55
+ };
56
+ credentialStatus: {
57
+ id: string;
58
+ type: string;
59
+ scope: string;
60
+ };
61
+ proof: {
62
+ type: string;
63
+ created: string;
64
+ proofPurpose: string;
65
+ jws: string;
66
+ };
67
+ };
68
+ };
69
+ };
70
+ data: {
71
+ type: string;
72
+ value: {
73
+ did: string;
74
+ url: string;
75
+ name: string;
76
+ };
77
+ };
78
+ hooks: {
79
+ name: string;
80
+ type: string;
81
+ hook: string;
82
+ }[];
83
+ };
84
+ export { v2 };
85
+ declare const _default: {
86
+ createNftFactoryItx: ({ meta, tokens, shares, issuers, serviceUrl, }: {
87
+ meta: import("../types").TBlockletMeta;
88
+ tokens: Pick<import("@abtnode/client").BlockletPaymentPrice, "address" | "value">[];
89
+ shares: {
90
+ value: number;
91
+ address: string;
92
+ }[];
93
+ issuers: string[];
94
+ serviceUrl: string;
95
+ }) => {
96
+ name: string;
97
+ description: string;
98
+ settlement: string;
99
+ limit: number;
100
+ trustedIssuers: string[];
101
+ input: {
102
+ tokens: Pick<import("@abtnode/client").BlockletPaymentPrice, "address" | "value">[];
103
+ assets: any[];
104
+ variables: any[];
105
+ };
106
+ output: {
107
+ issuer: string;
108
+ parent: string;
109
+ moniker: string;
110
+ readonly: boolean;
111
+ transferrable: boolean;
112
+ data: {
113
+ type: string;
114
+ value: {
115
+ '@context': string;
116
+ id: string;
117
+ tag: string[];
118
+ type: string[];
119
+ issuer: {
120
+ id: string;
121
+ pk: string;
122
+ name: string;
123
+ };
124
+ issuanceDate: string;
125
+ credentialSubject: {
126
+ id: string;
127
+ sn: string;
128
+ purchased: {
129
+ blocklet: {
130
+ id: string;
131
+ url: string;
132
+ name: string;
133
+ };
134
+ };
135
+ display: {
136
+ type: string;
137
+ content: string;
138
+ };
139
+ };
140
+ credentialStatus: {
141
+ id: string;
142
+ type: string;
143
+ scope: string;
144
+ };
145
+ proof: {
146
+ type: string;
147
+ created: string;
148
+ proofPurpose: string;
149
+ jws: string;
150
+ };
151
+ };
152
+ };
153
+ };
154
+ data: {
155
+ type: string;
156
+ value: {
157
+ did: string;
158
+ url: string;
159
+ name: string;
160
+ };
161
+ };
162
+ hooks: {
163
+ name: string;
164
+ type: string;
165
+ hook: string;
166
+ }[];
167
+ };
168
+ v2: {
169
+ createNftFactoryItx: ({ blockletMeta, ocapClient, issuers, storeUrl, }: {
170
+ blockletMeta: import("../types").TBlockletMeta;
171
+ ocapClient: any;
172
+ issuers: string[];
173
+ storeUrl: string;
174
+ }) => Promise<{
175
+ itx: any;
176
+ stores: {
177
+ id: string;
178
+ url: string;
179
+ }[];
180
+ shares: {
181
+ amount: string;
182
+ tokenAddress: string;
183
+ accountAddress: string;
184
+ }[];
185
+ }>;
186
+ verifyPaymentIntegrity: ({ integrity: expected, blockletMeta, ocapClient, storeId, }: {
187
+ integrity: string;
188
+ blockletMeta: import("../types").TBlockletMeta;
189
+ ocapClient: any;
190
+ storeId: string;
191
+ }) => Promise<string>;
192
+ verifyNftFactory: ({ factoryState, signerWallet, }: {
193
+ factoryState: {
194
+ data: {
195
+ value: string;
196
+ };
197
+ input?: any;
198
+ address?: string;
199
+ hooks?: {
200
+ type: string;
201
+ hook: string;
202
+ }[];
203
+ };
204
+ signerWallet: any;
205
+ }) => Promise<any>;
206
+ checkFreeBlocklet: (blockletMeta: import("../types").TBlockletMeta) => Promise<boolean>;
207
+ version: string;
208
+ _test: {
209
+ getPriceTokens: (meta: any, ocapClient: any) => Promise<any>;
210
+ getFactoryInput: (inputTokens: {
211
+ address: string;
212
+ value: string | number;
213
+ decimal: number;
214
+ }[], { formatToken }?: {
215
+ formatToken?: boolean;
216
+ }) => {
217
+ tokens: {
218
+ address: string;
219
+ value: string | number;
220
+ decimal: number;
221
+ }[];
222
+ assets: [];
223
+ variables: [];
224
+ };
225
+ getPaymentIntegrity: ({ contract, factoryInput, storeComponents, meta, client, storeId, }: {
226
+ contract?: string;
227
+ factoryInput?: any;
228
+ storeComponents?: any;
229
+ meta?: any;
230
+ client?: any;
231
+ storeId?: string;
232
+ }) => Promise<string>;
233
+ getComponents: (inputMeta: any) => Promise<{
234
+ components: import("./v2").Component[];
235
+ stores: import("./v2").Store[];
236
+ }>;
237
+ getContract: ({ meta, priceTokens, components, }: {
238
+ meta: import("../types").TBlockletMeta;
239
+ priceTokens: {
240
+ decimal: number;
241
+ }[];
242
+ components: any;
243
+ }) => Promise<{
244
+ code: string;
245
+ shares: {
246
+ amount: string;
247
+ tokenAddress: string;
248
+ accountAddress: string;
249
+ }[];
250
+ }>;
251
+ };
252
+ };
253
+ };
254
+ export default _default;
@@ -1,7 +1,14 @@
1
- const v1 = require('./v1');
2
- const v2 = require('./v2');
3
-
4
- module.exports = {
5
- createNftFactoryItx: v1.createNftFactoryItx, // for backward compatibility
6
- v2,
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.v2 = exports.createNftFactoryItx = void 0;
7
+ const v1_1 = __importDefault(require("./v1"));
8
+ const v2_1 = __importDefault(require("./v2"));
9
+ exports.v2 = v2_1.default;
10
+ exports.createNftFactoryItx = v1_1.default.createNftFactoryItx;
11
+ exports.default = {
12
+ createNftFactoryItx: exports.createNftFactoryItx,
13
+ v2: v2_1.default,
7
14
  };
@@ -0,0 +1,185 @@
1
+ import { BlockletPaymentPrice } from '@abtnode/client';
2
+ import { TBlockletMeta } from '../types';
3
+ declare const createShareContract: ({ tokens, shares, }: {
4
+ tokens?: Pick<BlockletPaymentPrice, 'address' | 'value'>[];
5
+ shares: {
6
+ value: number;
7
+ address: string;
8
+ }[];
9
+ }) => string;
10
+ declare const createNftFactoryItx: ({ meta, tokens, shares, issuers, serviceUrl, }: {
11
+ meta: TBlockletMeta;
12
+ tokens: Pick<BlockletPaymentPrice, 'address' | 'value'>[];
13
+ shares: {
14
+ value: number;
15
+ address: string;
16
+ }[];
17
+ issuers: string[];
18
+ serviceUrl: string;
19
+ }) => {
20
+ name: string;
21
+ description: string;
22
+ settlement: string;
23
+ limit: number;
24
+ trustedIssuers: string[];
25
+ input: {
26
+ tokens: Pick<BlockletPaymentPrice, "address" | "value">[];
27
+ assets: any[];
28
+ variables: any[];
29
+ };
30
+ output: {
31
+ issuer: string;
32
+ parent: string;
33
+ moniker: string;
34
+ readonly: boolean;
35
+ transferrable: boolean;
36
+ data: {
37
+ type: string;
38
+ value: {
39
+ '@context': string;
40
+ id: string;
41
+ tag: string[];
42
+ type: string[];
43
+ issuer: {
44
+ id: string;
45
+ pk: string;
46
+ name: string;
47
+ };
48
+ issuanceDate: string;
49
+ credentialSubject: {
50
+ id: string;
51
+ sn: string;
52
+ purchased: {
53
+ blocklet: {
54
+ id: string;
55
+ url: string;
56
+ name: string;
57
+ };
58
+ };
59
+ display: {
60
+ type: string;
61
+ content: string;
62
+ };
63
+ };
64
+ credentialStatus: {
65
+ id: string;
66
+ type: string;
67
+ scope: string;
68
+ };
69
+ proof: {
70
+ type: string;
71
+ created: string;
72
+ proofPurpose: string;
73
+ jws: string;
74
+ };
75
+ };
76
+ };
77
+ };
78
+ data: {
79
+ type: string;
80
+ value: {
81
+ did: string;
82
+ url: string;
83
+ name: string;
84
+ };
85
+ };
86
+ hooks: {
87
+ name: string;
88
+ type: string;
89
+ hook: string;
90
+ }[];
91
+ };
92
+ export { createShareContract };
93
+ export { createNftFactoryItx };
94
+ declare const _default: {
95
+ createShareContract: ({ tokens, shares, }: {
96
+ tokens?: Pick<BlockletPaymentPrice, "address" | "value">[];
97
+ shares: {
98
+ value: number;
99
+ address: string;
100
+ }[];
101
+ }) => string;
102
+ createNftFactoryItx: ({ meta, tokens, shares, issuers, serviceUrl, }: {
103
+ meta: TBlockletMeta;
104
+ tokens: Pick<BlockletPaymentPrice, "address" | "value">[];
105
+ shares: {
106
+ value: number;
107
+ address: string;
108
+ }[];
109
+ issuers: string[];
110
+ serviceUrl: string;
111
+ }) => {
112
+ name: string;
113
+ description: string;
114
+ settlement: string;
115
+ limit: number;
116
+ trustedIssuers: string[];
117
+ input: {
118
+ tokens: Pick<BlockletPaymentPrice, "address" | "value">[];
119
+ assets: any[];
120
+ variables: any[];
121
+ };
122
+ output: {
123
+ issuer: string;
124
+ parent: string;
125
+ moniker: string;
126
+ readonly: boolean;
127
+ transferrable: boolean;
128
+ data: {
129
+ type: string;
130
+ value: {
131
+ '@context': string;
132
+ id: string;
133
+ tag: string[];
134
+ type: string[];
135
+ issuer: {
136
+ id: string;
137
+ pk: string;
138
+ name: string;
139
+ };
140
+ issuanceDate: string;
141
+ credentialSubject: {
142
+ id: string;
143
+ sn: string;
144
+ purchased: {
145
+ blocklet: {
146
+ id: string;
147
+ url: string;
148
+ name: string;
149
+ };
150
+ };
151
+ display: {
152
+ type: string;
153
+ content: string;
154
+ };
155
+ };
156
+ credentialStatus: {
157
+ id: string;
158
+ type: string;
159
+ scope: string;
160
+ };
161
+ proof: {
162
+ type: string;
163
+ created: string;
164
+ proofPurpose: string;
165
+ jws: string;
166
+ };
167
+ };
168
+ };
169
+ };
170
+ data: {
171
+ type: string;
172
+ value: {
173
+ did: string;
174
+ url: string;
175
+ name: string;
176
+ };
177
+ };
178
+ hooks: {
179
+ name: string;
180
+ type: string;
181
+ hook: string;
182
+ }[];
183
+ };
184
+ };
185
+ export default _default;
package/lib/payment/v1.js CHANGED
@@ -1,85 +1,84 @@
1
- /* eslint-disable no-await-in-loop */
2
- const joinURL = require('url-join');
3
- const { BN } = require('@ocap/util');
4
- const { isValidFactory } = require('@ocap/asset');
5
- const { toFactoryAddress } = require('@arcblock/did-util');
6
- const { getBlockletPurchaseTemplate } = require('../nft-templates');
7
-
8
- const createShareContract = ({ tokens = [], shares = [] }) => {
9
- const zeroBN = new BN(0);
10
- const decimals = 1000000; // we only support 6 decimals on share ratio
11
- const decimalsBN = new BN(decimals);
12
-
13
- const contract = [];
14
- const shareSum = shares.reduce((sum, x) => sum + x.value, 0);
15
- if (shareSum > 1) {
16
- throw new Error('payment.share invalid: share sum should not be greater than 1');
17
- }
18
-
19
- if (Array.isArray(tokens)) {
20
- tokens.forEach(({ address: tokenAddress, value: valueItem }) => {
21
- const valueBN = new BN(valueItem);
22
- if (valueBN.lt(zeroBN)) {
23
- throw new Error('token price must be greater than or equal to zero');
24
- }
25
- shares.forEach(({ address, value }) => {
26
- const ratio = new BN(value * decimals);
27
- const amount = valueBN.mul(ratio).div(decimalsBN);
28
- contract.push(`transferToken('${tokenAddress}','${address}','${amount.toString()}')`);
29
- });
30
- });
31
- }
32
-
33
- return contract.join(';\n');
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
34
4
  };
35
-
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createNftFactoryItx = exports.createShareContract = void 0;
7
+ const url_join_1 = __importDefault(require("url-join"));
8
+ const util_1 = require("@ocap/util");
9
+ const asset_1 = require("@ocap/asset");
10
+ const did_util_1 = require("@arcblock/did-util");
11
+ const nft_templates_1 = require("../nft-templates");
12
+ const createShareContract = ({ tokens = [], shares = [], }) => {
13
+ const zeroBN = new util_1.BN(0);
14
+ const decimals = 1000000; // we only support 6 decimals on share ratio
15
+ const decimalsBN = new util_1.BN(decimals);
16
+ const contract = [];
17
+ const shareSum = shares.reduce((sum, x) => sum + x.value, 0);
18
+ if (shareSum > 1) {
19
+ throw new Error('payment.share invalid: share sum should not be greater than 1');
20
+ }
21
+ if (Array.isArray(tokens)) {
22
+ tokens.forEach(({ address: tokenAddress, value: valueItem }) => {
23
+ const valueBN = new util_1.BN(valueItem);
24
+ if (valueBN.lt(zeroBN)) {
25
+ throw new Error('token price must be greater than or equal to zero');
26
+ }
27
+ shares.forEach(({ address, value }) => {
28
+ const ratio = new util_1.BN(value * decimals);
29
+ const amount = valueBN.mul(ratio).div(decimalsBN);
30
+ contract.push(`transferToken('${tokenAddress}','${address}','${amount.toString()}')`);
31
+ });
32
+ });
33
+ }
34
+ return contract.join(';\n');
35
+ };
36
+ exports.createShareContract = createShareContract;
36
37
  // we need to ensure that blocklet purchase factory does not change across changes
37
- const createNftFactoryItx = ({ meta, tokens, shares, issuers, serviceUrl }) => {
38
- const factoryOutput = getBlockletPurchaseTemplate(serviceUrl);
39
- const itx = {
40
- name: meta.title || meta.name,
41
- description: `Purchase NFT factory for blocklet ${meta.name}`,
42
- settlement: 'instant',
43
- limit: 0,
44
- trustedIssuers: issuers,
45
- input: {
46
- tokens: [...tokens],
47
- assets: [],
48
- variables: [],
49
- },
50
- output: {
51
- issuer: '{{ctx.issuer.id}}',
52
- parent: '{{ctx.factory}}',
53
- moniker: 'BlockletPurchaseNFT',
54
- readonly: true,
55
- transferrable: false,
56
- data: factoryOutput,
57
- },
58
- data: {
59
- type: 'json',
60
- value: {
61
- did: meta.did,
62
- url: joinURL(serviceUrl, `/blocklet/${meta.did}`),
63
- name: meta.name,
64
- },
65
- },
66
- hooks: [
67
- {
68
- name: 'mint',
69
- type: 'contract',
70
- hook: createShareContract({ tokens, shares }),
71
- },
72
- ],
73
- };
74
-
75
- itx.address = toFactoryAddress(itx);
76
-
77
- isValidFactory(itx, true);
78
-
79
- return itx;
38
+ const createNftFactoryItx = ({ meta, tokens, shares, issuers, serviceUrl, }) => {
39
+ const factoryOutput = (0, nft_templates_1.getBlockletPurchaseTemplate)(serviceUrl);
40
+ const itx = {
41
+ name: meta.title || meta.name,
42
+ description: `Purchase NFT factory for blocklet ${meta.name}`,
43
+ settlement: 'instant',
44
+ limit: 0,
45
+ trustedIssuers: issuers,
46
+ input: {
47
+ tokens: [...tokens],
48
+ assets: [],
49
+ variables: [],
50
+ },
51
+ output: {
52
+ issuer: '{{ctx.issuer.id}}',
53
+ parent: '{{ctx.factory}}',
54
+ moniker: 'BlockletPurchaseNFT',
55
+ readonly: true,
56
+ transferrable: false,
57
+ data: factoryOutput,
58
+ },
59
+ data: {
60
+ type: 'json',
61
+ value: {
62
+ did: meta.did,
63
+ url: (0, url_join_1.default)(serviceUrl, `/blocklet/${meta.did}`),
64
+ name: meta.name,
65
+ },
66
+ },
67
+ hooks: [
68
+ {
69
+ name: 'mint',
70
+ type: 'contract',
71
+ hook: createShareContract({ tokens, shares }),
72
+ },
73
+ ],
74
+ };
75
+ // @ts-ignore
76
+ itx.address = (0, did_util_1.toFactoryAddress)(itx);
77
+ (0, asset_1.isValidFactory)(itx);
78
+ return itx;
80
79
  };
81
-
82
- module.exports = {
83
- createShareContract,
84
- createNftFactoryItx,
80
+ exports.createNftFactoryItx = createNftFactoryItx;
81
+ exports.default = {
82
+ createShareContract,
83
+ createNftFactoryItx,
85
84
  };