From ad47d9fffa471ccfd3b3e6b336a2e581c9b05463 Mon Sep 17 00:00:00 2001 From: RustemYuzlibaev Date: Wed, 17 Aug 2022 21:42:54 +0500 Subject: [PATCH 1/9] Create generateNftServiceKeypair.js --- scripts/generateNftServiceKeypair.js | 89 ++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 scripts/generateNftServiceKeypair.js diff --git a/scripts/generateNftServiceKeypair.js b/scripts/generateNftServiceKeypair.js new file mode 100644 index 000000000..2ed9a5916 --- /dev/null +++ b/scripts/generateNftServiceKeypair.js @@ -0,0 +1,89 @@ +import { KeyPair } from 'ucan-storage/keypair'; +import { build } from 'ucan-storage/ucan-storage'; + +const SERVICE_ENDPOINT = 'https://api.nft.storage'; // default +const API_TOKEN = process.env.API_KEY; + +/** + * Obtaining the service DID + * + */ +async function getServiceDid() { + const didRes = await fetch(new URL('/did', SERVICE_ENDPOINT)); + const { ok, value: serviceDid } = await didRes.json(); + + if (ok) { + return serviceDid; + } else { + throw new Error('Could not get Service DID'); + } +} + +/** + * Obtaining a root UCAN token. + * It will be valid for a duration of two weeks + * + */ +async function getRootToken(token) { + const ucanReq = await fetch(new URL('/ucan/token', SERVICE_ENDPOINT), { + method: 'POST', + headers: { + Authorization: `Bearer ${token}`, + }, + }); + + if (!ucanReq.ok) { + throw new Error('Failed to get root UCAN token'); + } + + const { value: rootUCAN } = await ucanReq.json(); + + return rootUCAN; +} + +/** + * Obtaining UCAN token with specified expiration date (10 days) + * + */ +async function getUCAN(kp, serviceDid, rootUCAN) { + // convert timestamp to seconds + const nowInSeconds = Math.floor(Date.now() / 1000); + const expiration = nowInSeconds + 864000; // 10 days from now + + try { + return await build({ + issuer: kp, + audience: serviceDid, + expiration: expiration, + capabilities: [ + { + with: `storage://${kp.did()}`, + can: 'upload/*', + }, + ], + proofs: [rootUCAN], + }); + } catch (error) { + throw new Error('Could not create UCAN token:', error); + } +} + +async function main() { + const pair = await KeyPair.create(); + const privateKey = pair.export(); + + const kp = await KeyPair.fromExportedKey(privateKey); + + const serviceDid = await getServiceDid(); + + const rootUCAN = await getRootToken(API_TOKEN); + + const ucan = await getUCAN(kp, serviceDid, rootUCAN); + + process.stdout.write(`{ + marketplaceDid: ${kp.did()}, + ucan: ${ucan} + }\n`); +} + +main().catch((error) => console.error(error)); From d36a13b0148e44222e39ed5ef859d76bfd97667d Mon Sep 17 00:00:00 2001 From: RustemYuzlibaev Date: Thu, 18 Aug 2022 13:38:16 +0500 Subject: [PATCH 2/9] add dep --- package.json | 1 + yarn.lock | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/package.json b/package.json index 1386994ed..0a3459266 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "echarts": "^5.3.2", "ethers": "^5.5.4", "lodash": "^4.17.21", + "ucan-storage": "^1.3.0", "vue": "^2.6.14", "vue-class-component": "^7.2.6", "vue-echarts": "^6.0.3", diff --git a/yarn.lock b/yarn.lock index 3070e850c..4ac9bf842 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1718,6 +1718,11 @@ multiformats "^9.5.4" murmurhash3js-revisited "^3.0.0" +"@noble/ed25519@^1.5.2": + version "1.6.1" + resolved "https://registry.yarnpkg.com/@noble/ed25519/-/ed25519-1.6.1.tgz#bad3e77008c7825a0859304ab8b4177703cd438d" + integrity sha512-Gptpue6qPmg7p1E5LBO5GDtXw5WMc2DVtUmu4EQequOcoCvum1dT9sY6s9M8aSJWq9YopCN4jmTOAvqMdw3q7w== + "@noble/hashes@1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.1.2.tgz#e9e035b9b166ca0af657a7848eb2718f0f22f183" @@ -4487,6 +4492,11 @@ base-x@^3.0.2: dependencies: safe-buffer "^5.0.1" +base-x@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/base-x/-/base-x-4.0.0.tgz#d0e3b7753450c73f8ad2389b5c018a4af7b2224a" + integrity sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw== + base64-js@^1.3.1, base64-js@^1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" @@ -10939,6 +10949,11 @@ move-file@^2.1.0: dependencies: path-exists "^4.0.0" +mri@^1.1.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/mri/-/mri-1.2.0.tgz#6721480fec2a11a4889861115a48b6cbe7cc8f0b" + integrity sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA== + ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" @@ -13005,6 +13020,13 @@ rxjs@^7.2.0, rxjs@^7.5.5: dependencies: tslib "^2.1.0" +sade@^1.8.1: + version "1.8.1" + resolved "https://registry.yarnpkg.com/sade/-/sade-1.8.1.tgz#0a78e81d658d394887be57d2a409bf703a3b2701" + integrity sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A== + dependencies: + mri "^1.1.0" + safari-14-idb-fix@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/safari-14-idb-fix/-/safari-14-idb-fix-3.0.0.tgz#450fc049b996ec7f3fd9ca2f89d32e0761583440" @@ -14376,6 +14398,15 @@ typescript@~4.4.4: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== +ucan-storage@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/ucan-storage/-/ucan-storage-1.3.0.tgz#b9f3e29fa77da22a636ba5d917f4e747da0a89c8" + integrity sha512-C1PvShqWTg6JzcBAuWDeCsaL6AggwsGWqbvKZ8XdN9csAukQVnA5/kerddhdPrpeoCGnJFfSkvBcPklZzdJ+OQ== + dependencies: + "@noble/ed25519" "^1.5.2" + base-x "^4.0.0" + sade "^1.8.1" + uglify-js@^3.1.4: version "3.14.2" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.14.2.tgz#d7dd6a46ca57214f54a2d0a43cad0f35db82ac99" From d57ecf411693a6e27c0b4983b48e85025a8b0e75 Mon Sep 17 00:00:00 2001 From: RustemYuzlibaev Date: Mon, 22 Aug 2022 14:06:54 +0300 Subject: [PATCH 3/9] write to file --- scripts/generateNftServiceKeypair.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/generateNftServiceKeypair.js b/scripts/generateNftServiceKeypair.js index 2ed9a5916..1c32433a6 100644 --- a/scripts/generateNftServiceKeypair.js +++ b/scripts/generateNftServiceKeypair.js @@ -1,3 +1,4 @@ +import { writeFile } from 'fs'; import { KeyPair } from 'ucan-storage/keypair'; import { build } from 'ucan-storage/ucan-storage'; @@ -80,10 +81,16 @@ async function main() { const ucan = await getUCAN(kp, serviceDid, rootUCAN); - process.stdout.write(`{ + const credentials = `{ marketplaceDid: ${kp.did()}, ucan: ${ucan} - }\n`); + }\n`; + + writeFile('ucan', credentials, (err) => { + if (err) throw new Error(err); + + process.stdout.write('The ucan file has been saved!'); + }); } main().catch((error) => console.error(error)); From c02ff2cd417241060d2776634c89ab65fef28235 Mon Sep 17 00:00:00 2001 From: RustemYuzlibaev Date: Tue, 23 Aug 2022 10:25:43 +0300 Subject: [PATCH 4/9] provide README --- package.json | 1 - scripts/ucan/README.md | 20 +++++ .../{ => ucan}/generateNftServiceKeypair.js | 9 +- scripts/ucan/package-lock.json | 83 +++++++++++++++++++ scripts/ucan/package.json | 19 +++++ yarn.lock | 31 ------- 6 files changed, 127 insertions(+), 36 deletions(-) create mode 100644 scripts/ucan/README.md rename scripts/{ => ucan}/generateNftServiceKeypair.js (91%) create mode 100644 scripts/ucan/package-lock.json create mode 100644 scripts/ucan/package.json diff --git a/package.json b/package.json index 0a3459266..1386994ed 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "echarts": "^5.3.2", "ethers": "^5.5.4", "lodash": "^4.17.21", - "ucan-storage": "^1.3.0", "vue": "^2.6.14", "vue-class-component": "^7.2.6", "vue-echarts": "^6.0.3", diff --git a/scripts/ucan/README.md b/scripts/ucan/README.md new file mode 100644 index 000000000..1dd09e54d --- /dev/null +++ b/scripts/ucan/README.md @@ -0,0 +1,20 @@ +## UCAN token generation script + +### Setup + +Before generation UCAN tokens it is neccessary to set API_KEY environment variable for this directory. +After that, installing dependencies is required by running: + +``` +npm install +``` + +Once the dependencies are installed it is possible to generate UCAN token. The output file (_ucan.json_) will be located in the same directory where scripts resides. + +### UCAN generation + +Run the command below to emit this file: + +``` +node generateNftServiceKeypair.js +``` diff --git a/scripts/generateNftServiceKeypair.js b/scripts/ucan/generateNftServiceKeypair.js similarity index 91% rename from scripts/generateNftServiceKeypair.js rename to scripts/ucan/generateNftServiceKeypair.js index 1c32433a6..ac785a63d 100644 --- a/scripts/generateNftServiceKeypair.js +++ b/scripts/ucan/generateNftServiceKeypair.js @@ -1,4 +1,5 @@ import { writeFile } from 'fs'; +import fetch from 'node-fetch'; import { KeyPair } from 'ucan-storage/keypair'; import { build } from 'ucan-storage/ucan-storage'; @@ -82,14 +83,14 @@ async function main() { const ucan = await getUCAN(kp, serviceDid, rootUCAN); const credentials = `{ - marketplaceDid: ${kp.did()}, - ucan: ${ucan} + "marketplaceDid": "${kp.did()}", + "ucan": "${ucan}" }\n`; - writeFile('ucan', credentials, (err) => { + writeFile('ucan.json', credentials, (err) => { if (err) throw new Error(err); - process.stdout.write('The ucan file has been saved!'); + process.stdout.write('The ucan file has been saved!\n'); }); } diff --git a/scripts/ucan/package-lock.json b/scripts/ucan/package-lock.json new file mode 100644 index 000000000..cc35e3e79 --- /dev/null +++ b/scripts/ucan/package-lock.json @@ -0,0 +1,83 @@ +{ + "name": "ucan", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@noble/ed25519": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/@noble/ed25519/-/ed25519-1.6.1.tgz", + "integrity": "sha512-Gptpue6qPmg7p1E5LBO5GDtXw5WMc2DVtUmu4EQequOcoCvum1dT9sY6s9M8aSJWq9YopCN4jmTOAvqMdw3q7w==" + }, + "base-x": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-4.0.0.tgz", + "integrity": "sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw==" + }, + "data-uri-to-buffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", + "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==" + }, + "fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "requires": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + } + }, + "formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "requires": { + "fetch-blob": "^3.1.2" + } + }, + "mri": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", + "integrity": "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==" + }, + "node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" + }, + "node-fetch": { + "version": "3.2.10", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.10.tgz", + "integrity": "sha512-MhuzNwdURnZ1Cp4XTazr69K0BTizsBroX7Zx3UgDSVcZYKF/6p0CBe4EUb/hLqmzVhl0UpYfgRljQ4yxE+iCxA==", + "requires": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + } + }, + "sade": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/sade/-/sade-1.8.1.tgz", + "integrity": "sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==", + "requires": { + "mri": "^1.1.0" + } + }, + "ucan-storage": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/ucan-storage/-/ucan-storage-1.3.0.tgz", + "integrity": "sha512-C1PvShqWTg6JzcBAuWDeCsaL6AggwsGWqbvKZ8XdN9csAukQVnA5/kerddhdPrpeoCGnJFfSkvBcPklZzdJ+OQ==", + "requires": { + "@noble/ed25519": "^1.5.2", + "base-x": "^4.0.0", + "sade": "^1.8.1" + } + }, + "web-streams-polyfill": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==" + } + } +} diff --git a/scripts/ucan/package.json b/scripts/ucan/package.json new file mode 100644 index 000000000..89f276cda --- /dev/null +++ b/scripts/ucan/package.json @@ -0,0 +1,19 @@ +{ + "name": "ucan", + "version": "1.0.0", + "description": "This script generates new ucan token for NFT marketplace each time it runs.", + "main": "generateNftServiceKeypair.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "ucan" + ], + "author": "", + "license": "ISC", + "dependencies": { + "node-fetch": "^3.2.10", + "ucan-storage": "^1.3.0" + }, + "type": "module" +} diff --git a/yarn.lock b/yarn.lock index 4ac9bf842..3070e850c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1718,11 +1718,6 @@ multiformats "^9.5.4" murmurhash3js-revisited "^3.0.0" -"@noble/ed25519@^1.5.2": - version "1.6.1" - resolved "https://registry.yarnpkg.com/@noble/ed25519/-/ed25519-1.6.1.tgz#bad3e77008c7825a0859304ab8b4177703cd438d" - integrity sha512-Gptpue6qPmg7p1E5LBO5GDtXw5WMc2DVtUmu4EQequOcoCvum1dT9sY6s9M8aSJWq9YopCN4jmTOAvqMdw3q7w== - "@noble/hashes@1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.1.2.tgz#e9e035b9b166ca0af657a7848eb2718f0f22f183" @@ -4492,11 +4487,6 @@ base-x@^3.0.2: dependencies: safe-buffer "^5.0.1" -base-x@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/base-x/-/base-x-4.0.0.tgz#d0e3b7753450c73f8ad2389b5c018a4af7b2224a" - integrity sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw== - base64-js@^1.3.1, base64-js@^1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" @@ -10949,11 +10939,6 @@ move-file@^2.1.0: dependencies: path-exists "^4.0.0" -mri@^1.1.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/mri/-/mri-1.2.0.tgz#6721480fec2a11a4889861115a48b6cbe7cc8f0b" - integrity sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA== - ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" @@ -13020,13 +13005,6 @@ rxjs@^7.2.0, rxjs@^7.5.5: dependencies: tslib "^2.1.0" -sade@^1.8.1: - version "1.8.1" - resolved "https://registry.yarnpkg.com/sade/-/sade-1.8.1.tgz#0a78e81d658d394887be57d2a409bf703a3b2701" - integrity sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A== - dependencies: - mri "^1.1.0" - safari-14-idb-fix@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/safari-14-idb-fix/-/safari-14-idb-fix-3.0.0.tgz#450fc049b996ec7f3fd9ca2f89d32e0761583440" @@ -14398,15 +14376,6 @@ typescript@~4.4.4: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== -ucan-storage@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/ucan-storage/-/ucan-storage-1.3.0.tgz#b9f3e29fa77da22a636ba5d917f4e747da0a89c8" - integrity sha512-C1PvShqWTg6JzcBAuWDeCsaL6AggwsGWqbvKZ8XdN9csAukQVnA5/kerddhdPrpeoCGnJFfSkvBcPklZzdJ+OQ== - dependencies: - "@noble/ed25519" "^1.5.2" - base-x "^4.0.0" - sade "^1.8.1" - uglify-js@^3.1.4: version "3.14.2" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.14.2.tgz#d7dd6a46ca57214f54a2d0a43cad0f35db82ac99" From 8eb9715b0244c12253f0c54aaf86c949126ba1cd Mon Sep 17 00:00:00 2001 From: RustemYuzlibaev Date: Tue, 23 Aug 2022 10:45:26 +0300 Subject: [PATCH 5/9] Update README.md --- scripts/ucan/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/ucan/README.md b/scripts/ucan/README.md index 1dd09e54d..cc7dadb8d 100644 --- a/scripts/ucan/README.md +++ b/scripts/ucan/README.md @@ -1,8 +1,10 @@ ## UCAN token generation script +The script is intended to emit UCAN tokens each 10 days. The output file (token) should be hosted at public route without any risk for the end-users. It will establish secure communication channel between NFT.Storage and Marketplace, and Marketplace and its end-users. + ### Setup -Before generation UCAN tokens it is neccessary to set API_KEY environment variable for this directory. +Before UCAN token generation it is neccessary to set API*KEY environment variable for this directory. (API_KEY could be get at \_nft.storage/manage* website per account) After that, installing dependencies is required by running: ``` From 5b542ca8898eaeb714b1621c28807b4e173675f2 Mon Sep 17 00:00:00 2001 From: RustemYuzlibaev Date: Tue, 23 Aug 2022 10:48:47 +0300 Subject: [PATCH 6/9] fix styling --- scripts/ucan/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ucan/README.md b/scripts/ucan/README.md index cc7dadb8d..8838d8362 100644 --- a/scripts/ucan/README.md +++ b/scripts/ucan/README.md @@ -4,7 +4,7 @@ The script is intended to emit UCAN tokens each 10 days. The output file (token) ### Setup -Before UCAN token generation it is neccessary to set API*KEY environment variable for this directory. (API_KEY could be get at \_nft.storage/manage* website per account) +Before UCAN token generation it is neccessary to set API_KEY environment variable for this directory. (API_KEY could be get at _nft.storage/manage_ website per account) After that, installing dependencies is required by running: ``` From d36335daa7b8b4fad8599cf56f8384dc98af0407 Mon Sep 17 00:00:00 2001 From: RustemYuzlibaev Date: Tue, 23 Aug 2022 10:55:47 +0300 Subject: [PATCH 7/9] Update README.md --- scripts/ucan/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ucan/README.md b/scripts/ucan/README.md index 8838d8362..e29f32d45 100644 --- a/scripts/ucan/README.md +++ b/scripts/ucan/README.md @@ -4,7 +4,7 @@ The script is intended to emit UCAN tokens each 10 days. The output file (token) ### Setup -Before UCAN token generation it is neccessary to set API_KEY environment variable for this directory. (API_KEY could be get at _nft.storage/manage_ website per account) +Before UCAN token generation it is neccessary to set API_KEY environment variable for this directory. (API_KEY could be get at `nft.storage/manage` website per account). After that, installing dependencies is required by running: ``` From 10f870a4f9568aa3d9bf9a7c6a68dc22608bc5e8 Mon Sep 17 00:00:00 2001 From: RustemYuzlibaev Date: Tue, 23 Aug 2022 11:31:26 +0300 Subject: [PATCH 8/9] Update README.md --- scripts/ucan/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ucan/README.md b/scripts/ucan/README.md index e29f32d45..57ee05a84 100644 --- a/scripts/ucan/README.md +++ b/scripts/ucan/README.md @@ -1,6 +1,6 @@ ## UCAN token generation script -The script is intended to emit UCAN tokens each 10 days. The output file (token) should be hosted at public route without any risk for the end-users. It will establish secure communication channel between NFT.Storage and Marketplace, and Marketplace and its end-users. +The script is intended to emit UCAN token which will be valid for 10 days. The output file (token) should be hosted at public route without any risk for the end-users. It will establish secure communication channel between NFT.Storage and Marketplace, and Marketplace and its end-users. ### Setup From 92d2bde80b23cf06131d475a6d7504ca297e0955 Mon Sep 17 00:00:00 2001 From: RustemYuzlibaev Date: Tue, 23 Aug 2022 16:47:53 +0300 Subject: [PATCH 9/9] use iife --- scripts/ucan/generateNftServiceKeypair.js | 38 ++++++++++++----------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/scripts/ucan/generateNftServiceKeypair.js b/scripts/ucan/generateNftServiceKeypair.js index ac785a63d..3e430d1b8 100644 --- a/scripts/ucan/generateNftServiceKeypair.js +++ b/scripts/ucan/generateNftServiceKeypair.js @@ -70,28 +70,30 @@ async function getUCAN(kp, serviceDid, rootUCAN) { } } -async function main() { - const pair = await KeyPair.create(); - const privateKey = pair.export(); - - const kp = await KeyPair.fromExportedKey(privateKey); +(async function main() { + try { + const pair = await KeyPair.create(); + const privateKey = pair.export(); - const serviceDid = await getServiceDid(); + const kp = await KeyPair.fromExportedKey(privateKey); - const rootUCAN = await getRootToken(API_TOKEN); + const serviceDid = await getServiceDid(); - const ucan = await getUCAN(kp, serviceDid, rootUCAN); + const rootUCAN = await getRootToken(API_TOKEN); - const credentials = `{ - "marketplaceDid": "${kp.did()}", - "ucan": "${ucan}" - }\n`; + const ucan = await getUCAN(kp, serviceDid, rootUCAN); - writeFile('ucan.json', credentials, (err) => { - if (err) throw new Error(err); + const credentials = `{ + "marketplaceDid": "${kp.did()}", + "ucan": "${ucan}" + }\n`; - process.stdout.write('The ucan file has been saved!\n'); - }); -} + writeFile('ucan.json', credentials, (err) => { + if (err) throw new Error(err); -main().catch((error) => console.error(error)); + process.stdout.write('The ucan file has been saved!\n'); + }); + } catch (error) { + console.error(error); + } +})();