diff --git a/examples/node/5-use-exported-account/6S5nrcLgUrhC2tLpaG83VLrMndnQ66DPTz7j6PoRnQjZKpvx.json b/examples/node/5-use-exported-account/6S5nrcLgUrhC2tLpaG83VLrMndnQ66DPTz7j6PoRnQjZKpvx.json index 3e2688e0..fd214064 100644 --- a/examples/node/5-use-exported-account/6S5nrcLgUrhC2tLpaG83VLrMndnQ66DPTz7j6PoRnQjZKpvx.json +++ b/examples/node/5-use-exported-account/6S5nrcLgUrhC2tLpaG83VLrMndnQ66DPTz7j6PoRnQjZKpvx.json @@ -1 +1,6 @@ -{"encoded":"kBkc/6ghJVs4thxE7ZMSRhxyVtYi2EzjJz8gvI2HfKQAgAAAAQAAAAgAAAAs5o9q7l+BpKkYsTXvuroLsxdysjikaK8qRkm13kzbnCfG5t9Df2QnQfHxrYyboPp5SoGdKxhnz5HRLK4/Fq1wPZpk43XSaa/b4PxOphxLfFYdjG2MJt80QSIzzRrP6TNj6R/YfMsKSySGqYHgiOkVnJJyZq0Exc35+3W6CyESzciXzDIw2iYzNdV5CJWpiAtgnW7tHxmsldKhUmYf","encoding":{"content":["pkcs8","ed25519"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"address":"5EdskhqqsNCUABVFhsZkxXfG2p4sRtf9ChU9iC5pE9bhx1kP","meta":{}} \ No newline at end of file +{ + "encoded": "kBkc/6ghJVs4thxE7ZMSRhxyVtYi2EzjJz8gvI2HfKQAgAAAAQAAAAgAAAAs5o9q7l+BpKkYsTXvuroLsxdysjikaK8qRkm13kzbnCfG5t9Df2QnQfHxrYyboPp5SoGdKxhnz5HRLK4/Fq1wPZpk43XSaa/b4PxOphxLfFYdjG2MJt80QSIzzRrP6TNj6R/YfMsKSySGqYHgiOkVnJJyZq0Exc35+3W6CyESzciXzDIw2iYzNdV5CJWpiAtgnW7tHxmsldKhUmYf", + "encoding": { "content": ["pkcs8", "ed25519"], "type": ["scrypt", "xsalsa20-poly1305"], "version": "3" }, + "address": "5EdskhqqsNCUABVFhsZkxXfG2p4sRtf9ChU9iC5pE9bhx1kP", + "meta": {} +} diff --git a/examples/node/5-use-exported-account/index.ts b/examples/node/5-use-exported-account/index.ts index b19f365d..2b1983d0 100644 --- a/examples/node/5-use-exported-account/index.ts +++ b/examples/node/5-use-exported-account/index.ts @@ -1,12 +1,7 @@ -import { - DdcClient, - File, - TESTNET, - JsonSigner, -} from '@cere-ddc-sdk/ddc-client'; +import { DdcClient, File, TESTNET, JsonSigner } from '@cere-ddc-sdk/ddc-client'; import * as fs from 'fs'; import path from 'path'; -import {fileURLToPath} from 'url'; +import { fileURLToPath } from 'url'; // The wallet should have enough CERE to pay for the transaction fees const pathToAccount = './6S5nrcLgUrhC2tLpaG83VLrMndnQ66DPTz7j6PoRnQjZKpvx.json'; @@ -20,14 +15,17 @@ const dir = path.dirname(fileURLToPath(import.meta.url)); // Create DDC client instance using JSON account exported from Cere Wallet const keyringPair = JSON.parse(fs.readFileSync(path.resolve(dir, pathToAccount)).toString()); -const jsonSigner = new JsonSigner(keyringPair, {passphrase: accountPassphrase}); +const jsonSigner = new JsonSigner(keyringPair, { passphrase: accountPassphrase }); const client = await DdcClient.create(jsonSigner, TESTNET); // Upload file const pathToFileToUpload = path.resolve(dir, '../assets/nature.jpg'); -const fileToUpload = new File(fs.createReadStream(pathToFileToUpload), {size: fs.statSync(pathToFileToUpload).size}); +const fileToUpload = new File(fs.createReadStream(pathToFileToUpload), { size: fs.statSync(pathToFileToUpload).size }); const uploadedFileUri = await client.store(bucketId, fileToUpload); -console.log('The file can be accessed by this URL', `https://cdn.testnet.cere.network/${bucketId}/${uploadedFileUri.cid}`); +console.log( + 'The file can be accessed by this URL', + `https://cdn.testnet.cere.network/${bucketId}/${uploadedFileUri.cid}`, +); console.log('File stored into bucket', bucketId, 'with CID', uploadedFileUri.cid); await client.disconnect(); diff --git a/examples/node/6-developer-console-compatibility/6S5nrcLgUrhC2tLpaG83VLrMndnQ66DPTz7j6PoRnQjZKpvx.json b/examples/node/6-developer-console-compatibility/6S5nrcLgUrhC2tLpaG83VLrMndnQ66DPTz7j6PoRnQjZKpvx.json index 3e2688e0..fd214064 100644 --- a/examples/node/6-developer-console-compatibility/6S5nrcLgUrhC2tLpaG83VLrMndnQ66DPTz7j6PoRnQjZKpvx.json +++ b/examples/node/6-developer-console-compatibility/6S5nrcLgUrhC2tLpaG83VLrMndnQ66DPTz7j6PoRnQjZKpvx.json @@ -1 +1,6 @@ -{"encoded":"kBkc/6ghJVs4thxE7ZMSRhxyVtYi2EzjJz8gvI2HfKQAgAAAAQAAAAgAAAAs5o9q7l+BpKkYsTXvuroLsxdysjikaK8qRkm13kzbnCfG5t9Df2QnQfHxrYyboPp5SoGdKxhnz5HRLK4/Fq1wPZpk43XSaa/b4PxOphxLfFYdjG2MJt80QSIzzRrP6TNj6R/YfMsKSySGqYHgiOkVnJJyZq0Exc35+3W6CyESzciXzDIw2iYzNdV5CJWpiAtgnW7tHxmsldKhUmYf","encoding":{"content":["pkcs8","ed25519"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"address":"5EdskhqqsNCUABVFhsZkxXfG2p4sRtf9ChU9iC5pE9bhx1kP","meta":{}} \ No newline at end of file +{ + "encoded": "kBkc/6ghJVs4thxE7ZMSRhxyVtYi2EzjJz8gvI2HfKQAgAAAAQAAAAgAAAAs5o9q7l+BpKkYsTXvuroLsxdysjikaK8qRkm13kzbnCfG5t9Df2QnQfHxrYyboPp5SoGdKxhnz5HRLK4/Fq1wPZpk43XSaa/b4PxOphxLfFYdjG2MJt80QSIzzRrP6TNj6R/YfMsKSySGqYHgiOkVnJJyZq0Exc35+3W6CyESzciXzDIw2iYzNdV5CJWpiAtgnW7tHxmsldKhUmYf", + "encoding": { "content": ["pkcs8", "ed25519"], "type": ["scrypt", "xsalsa20-poly1305"], "version": "3" }, + "address": "5EdskhqqsNCUABVFhsZkxXfG2p4sRtf9ChU9iC5pE9bhx1kP", + "meta": {} +} diff --git a/examples/node/6-developer-console-compatibility/index.ts b/examples/node/6-developer-console-compatibility/index.ts index 436acafb..299ef713 100644 --- a/examples/node/6-developer-console-compatibility/index.ts +++ b/examples/node/6-developer-console-compatibility/index.ts @@ -1,14 +1,6 @@ -import { - DdcClient, - File, - Link, - DagNodeUri, - DagNode, - JsonSigner, - TESTNET, -} from '@cere-ddc-sdk/ddc-client'; +import { DdcClient, File, Link, DagNodeUri, DagNode, JsonSigner, TESTNET } from '@cere-ddc-sdk/ddc-client'; import * as fs from 'fs'; -import {fileURLToPath} from 'url'; +import { fileURLToPath } from 'url'; import path from 'path'; // The wallet should have enough CERE to pay for the transaction fees @@ -26,8 +18,8 @@ const fileName = pathToFileToUpload.substring(pathToFileToUpload.lastIndexOf('/' // Initialise client using JSON account exported from Cere Wallet const keyringPair = JSON.parse(fs.readFileSync(path.resolve(dir, pathToAccount)).toString()); -const jsonSigner = new JsonSigner(keyringPair, {passphrase: accountPassphrase}); -const client = await DdcClient.create(jsonSigner, {...TESTNET, logLevel: 'fatal'}); +const jsonSigner = new JsonSigner(keyringPair, { passphrase: accountPassphrase }); +const client = await DdcClient.create(jsonSigner, { ...TESTNET, logLevel: 'fatal' }); // Upload file const fileSize = fs.statSync(pathToFileToUpload).size; @@ -36,20 +28,27 @@ const fileToUpload = new File(fs.createReadStream(pathToFileToUpload), { }); const uploadedFileUri = await client.store(bucketId, fileToUpload); console.log('File stored into bucket', bucketId, 'with CID', uploadedFileUri.cid); -console.log('The file can be accessed by this URL', `https://cdn.testnet.cere.network/${bucketId}/${uploadedFileUri.cid}`); +console.log( + 'The file can be accessed by this URL', + `https://cdn.testnet.cere.network/${bucketId}/${uploadedFileUri.cid}`, +); // Attach uploaded file to 'fs' DAG node (where 'fs' is a CNS name used by Developer Console to index files) const filePathInDeveloperConsole = 'photos/nature/'; -const rootDagNode = await client.read(new DagNodeUri(bucketId, 'fs'), {cacheControl: 'no-cache'}) - .catch((res) => { - if (res.message == 'Cannot resolve CNS name: "fs"') { - return new DagNode(null); - } else { - throw new Error('Failed to fetch \'fs\' DAG node'); - } - }); +const rootDagNode = await client.read(new DagNodeUri(bucketId, 'fs'), { cacheControl: 'no-cache' }).catch((res) => { + if (res.message == 'Cannot resolve CNS name: "fs"') { + return new DagNode(null); + } else { + throw new Error("Failed to fetch 'fs' DAG node"); + } +}); rootDagNode.links.push(new Link(uploadedFileUri.cid, fileSize, filePathInDeveloperConsole + fileName)); -await client.store(bucketId, rootDagNode, {name: 'fs'}); -console.log('The file can be found in developer console in bucket', bucketId, 'and path is', filePathInDeveloperConsole); +await client.store(bucketId, rootDagNode, { name: 'fs' }); +console.log( + 'The file can be found in developer console in bucket', + bucketId, + 'and path is', + filePathInDeveloperConsole, +); await client.disconnect();