@eluvio/elv-client-js 3.1.90 → 3.1.93
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/ElvClient-min.js +7 -7
- package/dist/ElvClient-node-min.js +12 -12
- package/dist/ElvFrameClient-min.js +6 -6
- package/dist/ElvPermissionsClient-min.js +5 -5
- package/dist/src/AuthorizationClient.js +2 -2
- package/dist/src/HttpClient.js +2 -2
- package/dist/src/UserProfileClient.js +31 -18
- package/dist/src/Utils.js +173 -1
- package/dist/src/client/ContentAccess.js +67 -50
- package/dist/src/client/ContentManagement.js +20 -12
- package/dist/src/client/NFT.js +23 -68
- package/package-lock.json +1 -1
- package/package.json +1 -1
- package/src/HttpClient.js +2 -2
- package/src/Utils.js +119 -0
- package/src/client/ContentAccess.js +17 -10
- package/src/client/NFT.js +14 -49
package/dist/src/client/NFT.js
CHANGED
|
@@ -25,9 +25,8 @@ var _require = require("../Validation"),
|
|
|
25
25
|
* @methodGroup Minting
|
|
26
26
|
* @namedParams
|
|
27
27
|
* @param {string} tenantId - The ID of the tenant
|
|
28
|
-
* @param {string=} email - The email of the NFT recipient
|
|
29
28
|
* @param {string=} address - The address of the NFT recipient
|
|
30
|
-
* @param {string}
|
|
29
|
+
* @param {string} marketplaceId - The ID of the marketplace containing the NFT
|
|
31
30
|
* @param {Array<Object>} items - List of items
|
|
32
31
|
* @param {string} items.sku - SKU of the NFT
|
|
33
32
|
* @param {number=} items.quantity=1 - Number to mint
|
|
@@ -40,59 +39,22 @@ var _require = require("../Validation"),
|
|
|
40
39
|
|
|
41
40
|
|
|
42
41
|
exports.MintNFT = function _callee(_ref) {
|
|
43
|
-
var tenantId,
|
|
42
|
+
var tenantId, address, marketplaceId, items, _ref$extraData, extraData, requestBody, transactionId, mintSignature;
|
|
44
43
|
|
|
45
44
|
return _regeneratorRuntime.async(function _callee$(_context) {
|
|
46
45
|
while (1) {
|
|
47
46
|
switch (_context.prev = _context.next) {
|
|
48
47
|
case 0:
|
|
49
|
-
tenantId = _ref.tenantId,
|
|
48
|
+
tenantId = _ref.tenantId, address = _ref.address, marketplaceId = _ref.marketplaceId, items = _ref.items, _ref$extraData = _ref.extraData, extraData = _ref$extraData === void 0 ? {} : _ref$extraData;
|
|
50
49
|
ValidatePresence("tenantId", tenantId);
|
|
51
|
-
ValidatePresence("
|
|
52
|
-
ValidatePresence("
|
|
50
|
+
ValidatePresence("address", address);
|
|
51
|
+
ValidatePresence("marketplaceId", marketplaceId);
|
|
53
52
|
ValidatePresence("items", items);
|
|
54
|
-
ValidateObject(
|
|
55
|
-
|
|
56
|
-
accountInitializationBody = {
|
|
57
|
-
ts: Date.now()
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
if (email) {
|
|
61
|
-
accountInitializationBody.email = email;
|
|
62
|
-
} else {
|
|
63
|
-
accountInitializationBody.addr = address;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
_context.next = 10;
|
|
67
|
-
return _regeneratorRuntime.awrap(this.Sign(JSON.stringify(accountInitializationBody)));
|
|
68
|
-
|
|
69
|
-
case 10:
|
|
70
|
-
accountInitializationSignature = _context.sent;
|
|
71
|
-
_context.t0 = _regeneratorRuntime;
|
|
72
|
-
_context.t1 = this.utils;
|
|
73
|
-
_context.next = 15;
|
|
74
|
-
return _regeneratorRuntime.awrap(this.authClient.MakeAuthServiceRequest({
|
|
75
|
-
method: "POST",
|
|
76
|
-
path: "/as/tnt/prov/eth/".concat(tenantId),
|
|
77
|
-
body: accountInitializationBody,
|
|
78
|
-
headers: {
|
|
79
|
-
"Authorization": "Bearer ".concat(accountInitializationSignature)
|
|
80
|
-
}
|
|
81
|
-
}));
|
|
82
|
-
|
|
83
|
-
case 15:
|
|
84
|
-
_context.t2 = _context.sent;
|
|
85
|
-
_context.t3 = _context.t1.ResponseToJson.call(_context.t1, _context.t2);
|
|
86
|
-
_context.next = 19;
|
|
87
|
-
return _context.t0.awrap.call(_context.t0, _context.t3);
|
|
88
|
-
|
|
89
|
-
case 19:
|
|
90
|
-
_ref2 = _context.sent;
|
|
91
|
-
addr = _ref2.addr;
|
|
92
|
-
address = this.utils.FormatAddress(addr);
|
|
53
|
+
ValidateObject(marketplaceId);
|
|
54
|
+
ValidateAddress(address);
|
|
93
55
|
requestBody = {
|
|
94
|
-
|
|
95
|
-
|
|
56
|
+
tickets: null,
|
|
57
|
+
products: items.map(function (item) {
|
|
96
58
|
return {
|
|
97
59
|
sku: item.sku,
|
|
98
60
|
quant: item.quantity || 1,
|
|
@@ -101,44 +63,37 @@ exports.MintNFT = function _callee(_ref) {
|
|
|
101
63
|
}) : _objectSpread({}, item.extraData || {})
|
|
102
64
|
};
|
|
103
65
|
}),
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
66
|
+
ident: address,
|
|
67
|
+
cust_name: address,
|
|
68
|
+
extra: _objectSpread({}, extraData, {
|
|
69
|
+
elv_addr: address
|
|
70
|
+
})
|
|
107
71
|
};
|
|
108
|
-
ValidateAddress(address);
|
|
109
|
-
|
|
110
|
-
if (email) {
|
|
111
|
-
requestBody.email = email;
|
|
112
|
-
} else {
|
|
113
|
-
requestBody.addr = address;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
requestBody.extra.elv_addr = address;
|
|
117
72
|
transactionId = this.utils.B58(UUID.parse(UUID.v4()));
|
|
118
73
|
requestBody.ts = Date.now();
|
|
119
74
|
requestBody.trans_id = transactionId;
|
|
120
|
-
_context.next =
|
|
75
|
+
_context.next = 13;
|
|
121
76
|
return _regeneratorRuntime.awrap(this.Sign(JSON.stringify(requestBody)));
|
|
122
77
|
|
|
123
|
-
case
|
|
78
|
+
case 13:
|
|
124
79
|
mintSignature = _context.sent;
|
|
125
|
-
_context.next =
|
|
80
|
+
_context.next = 16;
|
|
126
81
|
return _regeneratorRuntime.awrap(this.authClient.MakeAuthServiceRequest({
|
|
127
82
|
method: "POST",
|
|
128
|
-
path: "/as/
|
|
83
|
+
path: UrlJoin("/as/tnt/trans/base", tenantId, marketplaceId),
|
|
129
84
|
body: requestBody,
|
|
130
85
|
headers: {
|
|
131
86
|
"Authorization": "Bearer ".concat(mintSignature)
|
|
132
87
|
}
|
|
133
88
|
}));
|
|
134
89
|
|
|
135
|
-
case
|
|
90
|
+
case 16:
|
|
136
91
|
return _context.abrupt("return", {
|
|
137
92
|
address: address,
|
|
138
93
|
transactionId: transactionId
|
|
139
94
|
});
|
|
140
95
|
|
|
141
|
-
case
|
|
96
|
+
case 17:
|
|
142
97
|
case "end":
|
|
143
98
|
return _context.stop();
|
|
144
99
|
}
|
|
@@ -163,14 +118,14 @@ exports.MintNFT = function _callee(_ref) {
|
|
|
163
118
|
*/
|
|
164
119
|
|
|
165
120
|
|
|
166
|
-
exports.CollectionTransactions = function _callee2(
|
|
167
|
-
var tenantId, collectionId,
|
|
121
|
+
exports.CollectionTransactions = function _callee2(_ref2) {
|
|
122
|
+
var tenantId, collectionId, _ref2$filterOptions, filterOptions, ts, queryParams, allowedOptions, path, signature;
|
|
168
123
|
|
|
169
124
|
return _regeneratorRuntime.async(function _callee2$(_context2) {
|
|
170
125
|
while (1) {
|
|
171
126
|
switch (_context2.prev = _context2.next) {
|
|
172
127
|
case 0:
|
|
173
|
-
tenantId =
|
|
128
|
+
tenantId = _ref2.tenantId, collectionId = _ref2.collectionId, _ref2$filterOptions = _ref2.filterOptions, filterOptions = _ref2$filterOptions === void 0 ? {} : _ref2$filterOptions;
|
|
174
129
|
ts = Date.now();
|
|
175
130
|
queryParams = {
|
|
176
131
|
ts: ts
|
package/package-lock.json
CHANGED
package/package.json
CHANGED
package/src/HttpClient.js
CHANGED
|
@@ -77,10 +77,10 @@ class HttpClient {
|
|
|
77
77
|
headers: this.RequestHeaders(bodyType, headers)
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
-
if(method === "POST" || method === "PUT") {
|
|
80
|
+
if(method === "POST" || method === "PUT" || method === "DELETE") {
|
|
81
81
|
if(body && bodyType === "JSON") {
|
|
82
82
|
fetchParameters.body = JSON.stringify(body);
|
|
83
|
-
} else {
|
|
83
|
+
} else if(body) {
|
|
84
84
|
fetchParameters.body = body;
|
|
85
85
|
}
|
|
86
86
|
}
|
package/src/Utils.js
CHANGED
|
@@ -150,6 +150,125 @@ const Utils = {
|
|
|
150
150
|
};
|
|
151
151
|
},
|
|
152
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Decode the specified write token into its component parts
|
|
155
|
+
*
|
|
156
|
+
* @param writeToken
|
|
157
|
+
*
|
|
158
|
+
* @returns {Object} - Components of the write token.
|
|
159
|
+
*/
|
|
160
|
+
DecodeWriteToken: (writeToken) => {
|
|
161
|
+
/*
|
|
162
|
+
Format:
|
|
163
|
+
- content write token, LRO:
|
|
164
|
+
- prefix: "tq__", "tqw__", "tlro"
|
|
165
|
+
- format:
|
|
166
|
+
prefix + base58(uvarint(len(QID) | QID |
|
|
167
|
+
uvarint(len(NID) | NID |
|
|
168
|
+
uvarint(len(RAND_BYTES) | RAND_BYTES)
|
|
169
|
+
- content part write token:
|
|
170
|
+
- prefix: "tqp_"
|
|
171
|
+
- format:
|
|
172
|
+
prefix + base58(scheme | flags | uvarint(len(RAND_BYTES) | RAND_BYTES)
|
|
173
|
+
- content write token v1, content part write token v1:
|
|
174
|
+
- prefix: "tqw_", "tqpw"
|
|
175
|
+
- format:
|
|
176
|
+
prefix + base58(RAND_BYTES)
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
if(writeToken.length<4){
|
|
180
|
+
throw new Error(`Invalid write token: ["${writeToken}"] (unknown prefix)`);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
let tokenType;
|
|
184
|
+
|
|
185
|
+
if(writeToken.startsWith("tqw__")) {
|
|
186
|
+
tokenType = "tq__";
|
|
187
|
+
writeToken = writeToken.slice(5);
|
|
188
|
+
} else {
|
|
189
|
+
tokenType = writeToken.slice(0, 4);
|
|
190
|
+
writeToken = writeToken.slice(4);
|
|
191
|
+
}
|
|
192
|
+
if(writeToken.length===0){
|
|
193
|
+
throw new Error(`Invalid write token: ["${writeToken}"] (too short)`);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
switch(tokenType) {
|
|
197
|
+
case "tqw_":
|
|
198
|
+
case "tq__":
|
|
199
|
+
case "tqpw":
|
|
200
|
+
case "tqp_":
|
|
201
|
+
case "tlro":
|
|
202
|
+
break;
|
|
203
|
+
default:
|
|
204
|
+
throw new Error(`Invalid write token: ["${writeToken}"] (unknown prefix)`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// decode base58 payload
|
|
208
|
+
let bytes = Utils.FromB58(writeToken);
|
|
209
|
+
|
|
210
|
+
function decodeBytes(isID, prefix) {
|
|
211
|
+
let bsize = VarInt.decode(bytes,0); // decode: count of bytes to read
|
|
212
|
+
let offset = VarInt.decode.bytes; // offset in buffer to start read after decode
|
|
213
|
+
let theBytes;
|
|
214
|
+
let ret;
|
|
215
|
+
|
|
216
|
+
if(isID) {
|
|
217
|
+
theBytes = bytes.slice(offset+1, bsize+offset); // skip 1st byte (code id) at offset 0
|
|
218
|
+
if(theBytes.length===0){
|
|
219
|
+
ret = "";
|
|
220
|
+
} else {
|
|
221
|
+
ret = prefix + Utils.B58(theBytes);
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
theBytes = bytes.slice(offset, bsize+offset);
|
|
225
|
+
ret = "0x" + theBytes.toString("hex");
|
|
226
|
+
}
|
|
227
|
+
bytes = bytes.slice(bsize+offset);
|
|
228
|
+
return ret;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
let tokenId;
|
|
232
|
+
let qid;
|
|
233
|
+
let nid;
|
|
234
|
+
let scheme;
|
|
235
|
+
let flags;
|
|
236
|
+
|
|
237
|
+
switch(tokenType) {
|
|
238
|
+
case "tqw_": // content write token v1
|
|
239
|
+
case "tqpw": // content part write token v1
|
|
240
|
+
tokenId = "0x" + bytes.toString("hex");
|
|
241
|
+
break;
|
|
242
|
+
case "tlro": // LRO,
|
|
243
|
+
case "tq__": // content write token
|
|
244
|
+
qid = decodeBytes(true, "iq__");
|
|
245
|
+
nid = decodeBytes(true, "inod");
|
|
246
|
+
tokenId = decodeBytes(false, "");
|
|
247
|
+
break;
|
|
248
|
+
case "tqp_": // content part write token
|
|
249
|
+
if(bytes.length<3) {
|
|
250
|
+
throw new Error(`Invalid write token: ["${writeToken}"] (token truncated)`);
|
|
251
|
+
}
|
|
252
|
+
scheme=bytes[0];
|
|
253
|
+
flags=bytes[1];
|
|
254
|
+
bytes = bytes.slice(2);
|
|
255
|
+
tokenId = decodeBytes(false, "");
|
|
256
|
+
break;
|
|
257
|
+
default:
|
|
258
|
+
// already raised
|
|
259
|
+
throw new Error(`Invalid write token: ["${writeToken}"] (unknown prefix)`);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
tokenType: tokenType, // type of token
|
|
264
|
+
tokenId: tokenId, // random bytes generated by the fabric node
|
|
265
|
+
objectId: qid, // content id for content write token (tq__) or LRO (tlro)
|
|
266
|
+
nodeId: nid, // node id where the content write token is valid (tq__)
|
|
267
|
+
scheme, // encryption scheme for part write token - (tqp_)
|
|
268
|
+
flags // flags for part write token (tqp_)
|
|
269
|
+
};
|
|
270
|
+
},
|
|
271
|
+
|
|
153
272
|
/**
|
|
154
273
|
* Convert contract address to multiformat hash
|
|
155
274
|
*
|
|
@@ -234,11 +234,14 @@ exports.ContentType = async function({name, typeId, versionHash, publicOnly=fals
|
|
|
234
234
|
if(name) {
|
|
235
235
|
this.Log("Looking up type by name in content space metadata...");
|
|
236
236
|
// Look up named type in content space metadata
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
237
|
+
try {
|
|
238
|
+
typeId = await this.ContentObjectMetadata({
|
|
239
|
+
libraryId: this.contentSpaceLibraryId,
|
|
240
|
+
objectId: this.contentSpaceObjectId,
|
|
241
|
+
metadataSubtree: UrlJoin("public", "contentTypes", name)
|
|
242
|
+
});
|
|
243
|
+
// eslint-disable-next-line no-empty
|
|
244
|
+
} catch(error) {}
|
|
242
245
|
}
|
|
243
246
|
|
|
244
247
|
if(!typeId) {
|
|
@@ -310,11 +313,15 @@ exports.ContentTypes = async function() {
|
|
|
310
313
|
this.Log(typeAddresses);
|
|
311
314
|
|
|
312
315
|
// Content space types
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
316
|
+
let contentSpaceTypes = {};
|
|
317
|
+
try {
|
|
318
|
+
contentSpaceTypes = await this.ContentObjectMetadata({
|
|
319
|
+
libraryId: this.contentSpaceLibraryId,
|
|
320
|
+
objectId: this.contentSpaceObjectId,
|
|
321
|
+
metadataSubtree: "public/contentTypes"
|
|
322
|
+
}) || {};
|
|
323
|
+
// eslint-disable-next-line no-empty
|
|
324
|
+
} catch(error) {}
|
|
318
325
|
|
|
319
326
|
const contentSpaceTypeAddresses = Object.values(contentSpaceTypes)
|
|
320
327
|
.map(typeId => this.utils.HashToAddress(typeId));
|
package/src/client/NFT.js
CHANGED
|
@@ -18,9 +18,8 @@ const {
|
|
|
18
18
|
* @methodGroup Minting
|
|
19
19
|
* @namedParams
|
|
20
20
|
* @param {string} tenantId - The ID of the tenant
|
|
21
|
-
* @param {string=} email - The email of the NFT recipient
|
|
22
21
|
* @param {string=} address - The address of the NFT recipient
|
|
23
|
-
* @param {string}
|
|
22
|
+
* @param {string} marketplaceId - The ID of the marketplace containing the NFT
|
|
24
23
|
* @param {Array<Object>} items - List of items
|
|
25
24
|
* @param {string} items.sku - SKU of the NFT
|
|
26
25
|
* @param {number=} items.quantity=1 - Number to mint
|
|
@@ -30,66 +29,32 @@ const {
|
|
|
30
29
|
*
|
|
31
30
|
* @return Promise<Object> - An object containing the address for whom the NFT was minted and the transactionId of the minting request.
|
|
32
31
|
*/
|
|
33
|
-
exports.MintNFT = async function({tenantId,
|
|
32
|
+
exports.MintNFT = async function({tenantId, address, marketplaceId, items, extraData={}}) {
|
|
34
33
|
ValidatePresence("tenantId", tenantId);
|
|
35
|
-
ValidatePresence("
|
|
36
|
-
ValidatePresence("
|
|
34
|
+
ValidatePresence("address", address);
|
|
35
|
+
ValidatePresence("marketplaceId", marketplaceId);
|
|
37
36
|
ValidatePresence("items", items);
|
|
38
37
|
|
|
39
|
-
ValidateObject(
|
|
40
|
-
|
|
41
|
-
// If address not specified, make call to initialize address for email
|
|
42
|
-
let accountInitializationBody = { ts: Date.now() };
|
|
43
|
-
if(email) {
|
|
44
|
-
accountInitializationBody.email = email;
|
|
45
|
-
} else {
|
|
46
|
-
accountInitializationBody.addr = address;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const accountInitializationSignature = await this.Sign(
|
|
50
|
-
JSON.stringify(accountInitializationBody)
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const {addr} = await this.utils.ResponseToJson(
|
|
54
|
-
await this.authClient.MakeAuthServiceRequest({
|
|
55
|
-
method: "POST",
|
|
56
|
-
path: `/as/tnt/prov/eth/${tenantId}`,
|
|
57
|
-
body: accountInitializationBody,
|
|
58
|
-
headers: {
|
|
59
|
-
"Authorization": `Bearer ${accountInitializationSignature}`
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
address = this.utils.FormatAddress(addr);
|
|
38
|
+
ValidateObject(marketplaceId);
|
|
39
|
+
ValidateAddress(address);
|
|
65
40
|
|
|
66
41
|
let requestBody = {
|
|
67
|
-
|
|
68
|
-
|
|
42
|
+
tickets: null,
|
|
43
|
+
products: items.map(item => ({
|
|
69
44
|
sku: item.sku,
|
|
70
45
|
quant: item.quantity || 1,
|
|
71
46
|
extra: item.tokenId ?
|
|
72
47
|
{ ...(item.extraData || {}), token_id: item.tokenId } :
|
|
73
48
|
{ ...(item.extraData || {}) }
|
|
74
49
|
})),
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
...extraData
|
|
50
|
+
ident: address,
|
|
51
|
+
cust_name: address,
|
|
52
|
+
extra: {
|
|
53
|
+
...extraData,
|
|
54
|
+
elv_addr: address
|
|
79
55
|
}
|
|
80
56
|
};
|
|
81
57
|
|
|
82
|
-
|
|
83
|
-
ValidateAddress(address);
|
|
84
|
-
|
|
85
|
-
if(email) {
|
|
86
|
-
requestBody.email = email;
|
|
87
|
-
} else {
|
|
88
|
-
requestBody.addr = address;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
requestBody.extra.elv_addr = address;
|
|
92
|
-
|
|
93
58
|
const transactionId = this.utils.B58(UUID.parse(UUID.v4()));
|
|
94
59
|
requestBody.ts = Date.now();
|
|
95
60
|
requestBody.trans_id = transactionId;
|
|
@@ -100,7 +65,7 @@ exports.MintNFT = async function({tenantId, email, address, collectionId, items,
|
|
|
100
65
|
|
|
101
66
|
await this.authClient.MakeAuthServiceRequest({
|
|
102
67
|
method: "POST",
|
|
103
|
-
path:
|
|
68
|
+
path: UrlJoin("/as/tnt/trans/base", tenantId, marketplaceId),
|
|
104
69
|
body: requestBody,
|
|
105
70
|
headers: {
|
|
106
71
|
"Authorization": `Bearer ${mintSignature}`
|