@blocklet/meta 1.15.17 → 1.16.0-beta-b16cb035

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 (62) hide show
  1. package/lib/channel.d.ts +32 -0
  2. package/lib/channel.js +54 -0
  3. package/lib/constants.d.ts +2 -0
  4. package/lib/constants.js +5 -152
  5. package/lib/did.d.ts +3 -0
  6. package/lib/did.js +9 -9
  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 +14 -0
  12. package/lib/extension.js +82 -77
  13. package/lib/file.d.ts +23 -0
  14. package/lib/file.js +51 -36
  15. package/lib/fix.d.ts +36 -0
  16. package/lib/fix.js +231 -228
  17. package/lib/get-component-process-id.d.ts +5 -0
  18. package/lib/get-component-process-id.js +16 -0
  19. package/lib/has-reserved-key.d.ts +3 -0
  20. package/lib/has-reserved-key.js +15 -0
  21. package/lib/index.d.ts +86 -0
  22. package/lib/index.js +55 -34
  23. package/lib/info.d.ts +15 -0
  24. package/lib/info.js +70 -38
  25. package/lib/name.d.ts +15 -0
  26. package/lib/name.js +41 -8
  27. package/lib/nft-templates.d.ts +86 -0
  28. package/lib/nft-templates.js +52 -0
  29. package/lib/parse-navigation-from-blocklet.d.ts +92 -0
  30. package/lib/parse-navigation-from-blocklet.js +539 -0
  31. package/lib/parse-navigation.d.ts +3 -0
  32. package/lib/parse-navigation.js +197 -0
  33. package/lib/parse.d.ts +22 -0
  34. package/lib/parse.js +100 -89
  35. package/lib/payment/index.d.ts +254 -0
  36. package/lib/payment/index.js +14 -0
  37. package/lib/payment/v1.d.ts +185 -0
  38. package/lib/payment/v1.js +84 -0
  39. package/lib/payment/v2.d.ts +242 -0
  40. package/lib/payment/v2.js +576 -0
  41. package/lib/schema.d.ts +63 -0
  42. package/lib/schema.js +669 -283
  43. package/lib/service.d.ts +27 -0
  44. package/lib/service.js +71 -0
  45. package/lib/types/index.d.ts +1 -0
  46. package/lib/types/index.js +18 -0
  47. package/lib/types/schema.d.ts +284 -0
  48. package/lib/types/schema.js +3 -0
  49. package/lib/url-friendly.d.ts +6 -0
  50. package/lib/url-friendly.js +20 -0
  51. package/lib/util-meta.d.ts +42 -0
  52. package/lib/util-meta.js +146 -0
  53. package/lib/util.d.ts +201 -0
  54. package/lib/util.js +501 -82
  55. package/lib/validate.d.ts +13 -0
  56. package/lib/validate.js +37 -61
  57. package/lib/verify-multi-sig.d.ts +3 -0
  58. package/lib/verify-multi-sig.js +86 -59
  59. package/lib/wallet.d.ts +9 -0
  60. package/lib/wallet.js +19 -30
  61. package/package.json +59 -20
  62. package/lib/payment.js +0 -114
@@ -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;
@@ -0,0 +1,84 @@
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.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;
37
+ // we need to ensure that blocklet purchase factory does not change across changes
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;
79
+ };
80
+ exports.createNftFactoryItx = createNftFactoryItx;
81
+ exports.default = {
82
+ createShareContract,
83
+ createNftFactoryItx,
84
+ };
@@ -0,0 +1,242 @@
1
+ import { TBlockletMeta } from '../types';
2
+ declare const VERSION = "2.0.0";
3
+ export interface Store {
4
+ id: string;
5
+ pk: string;
6
+ url: string;
7
+ components: Array<{
8
+ did: string;
9
+ version: string;
10
+ }>;
11
+ }
12
+ export interface Component {
13
+ meta: TBlockletMeta;
14
+ storeInfo: {
15
+ id: string;
16
+ pk: string;
17
+ };
18
+ storeUrl: string;
19
+ children: Component[];
20
+ }
21
+ /**
22
+ * Used by CLI and Store to independent compute factory itx
23
+ *
24
+ * @param {{
25
+ * blockletMeta: TBlockletMeta,
26
+ * ocapClient: OcapClient,
27
+ * issuers: Array<string>,
28
+ * storeUrl: string,
29
+ * }}
30
+ * @returns {{
31
+ * itx: Itx
32
+ * store: Array<{id, url}>
33
+ * shares: Array<{
34
+ * accountName: string
35
+ * accountAddress: DID
36
+ * tokenAddress: DID
37
+ * amount: string|number,
38
+ * }>
39
+ * }}
40
+ */
41
+ declare const createNftFactoryItx: ({ blockletMeta, ocapClient, issuers, storeUrl, }: {
42
+ blockletMeta: TBlockletMeta;
43
+ ocapClient: any;
44
+ issuers: string[];
45
+ storeUrl: string;
46
+ }) => Promise<{
47
+ itx: any;
48
+ stores: {
49
+ id: string;
50
+ url: string;
51
+ }[];
52
+ shares: {
53
+ amount: string;
54
+ tokenAddress: string;
55
+ accountAddress: string;
56
+ }[];
57
+ }>;
58
+ /**
59
+ * Used by Store before generating payment signature
60
+ *
61
+ * @param {{
62
+ * integrity: string,
63
+ * blockletMeta: TBlockletMeta,
64
+ * ocapClient: OcapClient,
65
+ * storeId: string
66
+ * }}
67
+ * @returns {string} integrity
68
+ */
69
+ declare const verifyPaymentIntegrity: ({ integrity: expected, blockletMeta, ocapClient, storeId, }: {
70
+ integrity: string;
71
+ blockletMeta: TBlockletMeta;
72
+ ocapClient: any;
73
+ storeId: string;
74
+ }) => Promise<string>;
75
+ /**
76
+ * Used by Store before generating downloadToken
77
+ *
78
+ * @param {{
79
+ * {FactoryState} factoryState
80
+ * {Wallet} signerWallet
81
+ * }}
82
+ *
83
+ * @returns {{
84
+ * components: Array<{did: string, version: string}>
85
+ * }}
86
+ */
87
+ declare const verifyNftFactory: ({ factoryState, signerWallet, }: {
88
+ factoryState: {
89
+ data: {
90
+ value: string;
91
+ };
92
+ input?: any;
93
+ address?: string;
94
+ hooks?: Array<{
95
+ type: string;
96
+ hook: string;
97
+ }>;
98
+ };
99
+ signerWallet: any;
100
+ }) => Promise<any>;
101
+ /**
102
+ * Check blocklet and all of components are free
103
+ * Throw Error if not free
104
+ *
105
+ * @param {TBlockletMeta} meta
106
+ */
107
+ declare const checkFreeBlocklet: (blockletMeta: TBlockletMeta) => Promise<boolean>;
108
+ export declare const _test: {
109
+ getPriceTokens: (meta: any, ocapClient: any) => Promise<any>;
110
+ getFactoryInput: (inputTokens: Array<{
111
+ address: string;
112
+ value: string | number;
113
+ decimal: number;
114
+ }>, { formatToken }?: {
115
+ formatToken?: boolean;
116
+ }) => {
117
+ tokens: Array<{
118
+ address: string;
119
+ value: string | number;
120
+ decimal: number;
121
+ }>;
122
+ assets: [];
123
+ variables: [];
124
+ };
125
+ getPaymentIntegrity: ({ contract, factoryInput, storeComponents, meta, client, storeId, }: {
126
+ contract?: string;
127
+ factoryInput?: any;
128
+ storeComponents?: any;
129
+ meta?: any;
130
+ client?: any;
131
+ storeId?: string;
132
+ }) => Promise<string>;
133
+ getComponents: (inputMeta: any) => Promise<{
134
+ components: Component[];
135
+ stores: Store[];
136
+ }>;
137
+ getContract: ({ meta, priceTokens, components, }: {
138
+ meta: TBlockletMeta;
139
+ priceTokens: Array<{
140
+ decimal: number;
141
+ }>;
142
+ components: any;
143
+ }) => Promise<{
144
+ code: string;
145
+ shares: {
146
+ amount: string;
147
+ tokenAddress: string;
148
+ accountAddress: string;
149
+ }[];
150
+ }>;
151
+ };
152
+ export { createNftFactoryItx };
153
+ export { verifyPaymentIntegrity };
154
+ export { verifyNftFactory };
155
+ export { checkFreeBlocklet };
156
+ export { VERSION as version };
157
+ declare const _default: {
158
+ createNftFactoryItx: ({ blockletMeta, ocapClient, issuers, storeUrl, }: {
159
+ blockletMeta: TBlockletMeta;
160
+ ocapClient: any;
161
+ issuers: string[];
162
+ storeUrl: string;
163
+ }) => Promise<{
164
+ itx: any;
165
+ stores: {
166
+ id: string;
167
+ url: string;
168
+ }[];
169
+ shares: {
170
+ amount: string;
171
+ tokenAddress: string;
172
+ accountAddress: string;
173
+ }[];
174
+ }>;
175
+ verifyPaymentIntegrity: ({ integrity: expected, blockletMeta, ocapClient, storeId, }: {
176
+ integrity: string;
177
+ blockletMeta: TBlockletMeta;
178
+ ocapClient: any;
179
+ storeId: string;
180
+ }) => Promise<string>;
181
+ verifyNftFactory: ({ factoryState, signerWallet, }: {
182
+ factoryState: {
183
+ data: {
184
+ value: string;
185
+ };
186
+ input?: any;
187
+ address?: string;
188
+ hooks?: {
189
+ type: string;
190
+ hook: string;
191
+ }[];
192
+ };
193
+ signerWallet: any;
194
+ }) => Promise<any>;
195
+ checkFreeBlocklet: (blockletMeta: TBlockletMeta) => Promise<boolean>;
196
+ version: string;
197
+ _test: {
198
+ getPriceTokens: (meta: any, ocapClient: any) => Promise<any>;
199
+ getFactoryInput: (inputTokens: {
200
+ address: string;
201
+ value: string | number;
202
+ decimal: number;
203
+ }[], { formatToken }?: {
204
+ formatToken?: boolean;
205
+ }) => {
206
+ tokens: {
207
+ address: string;
208
+ value: string | number;
209
+ decimal: number;
210
+ }[];
211
+ assets: [];
212
+ variables: [];
213
+ };
214
+ getPaymentIntegrity: ({ contract, factoryInput, storeComponents, meta, client, storeId, }: {
215
+ contract?: string;
216
+ factoryInput?: any;
217
+ storeComponents?: any;
218
+ meta?: any;
219
+ client?: any;
220
+ storeId?: string;
221
+ }) => Promise<string>;
222
+ getComponents: (inputMeta: any) => Promise<{
223
+ components: Component[];
224
+ stores: Store[];
225
+ }>;
226
+ getContract: ({ meta, priceTokens, components, }: {
227
+ meta: TBlockletMeta;
228
+ priceTokens: {
229
+ decimal: number;
230
+ }[];
231
+ components: any;
232
+ }) => Promise<{
233
+ code: string;
234
+ shares: {
235
+ amount: string;
236
+ tokenAddress: string;
237
+ accountAddress: string;
238
+ }[];
239
+ }>;
240
+ };
241
+ };
242
+ export default _default;