Skip to content

Commit

Permalink
simplifies verifyMetadata sample
Browse files Browse the repository at this point in the history
updates dependencies

Signed-off-by: stadolf <stadolf@gmail.com>
  • Loading branch information
elmariachi111 committed Jul 28, 2023
1 parent b90cf62 commit 99683e8
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1,599 deletions.
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
"name": "boo",
"name": "ipnft-samples",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"dotenv": "^16.0.3",
"multiformats": "^11.0.0",
"node-fetch": "^3.3.0",
"dotenv": "^16.3.1",
"multiformats": "^12.0.1",
"ts-node": "^10.9.1",
"typescript": "^4.9.4",
"web3.storage": "^4.4.0"
"typescript": "^4.9.5",
"web3.storage": "^4.5.5"
},
"devDependencies": {
"@types/node": "^18.11.18"
"@types/node": "^18.16.0"
}
}
38 changes: 13 additions & 25 deletions verifyMetadata.mts
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
/// <reference lib="dom" />
import dotenv from "dotenv";
import { Web3Storage } from "web3.storage";
import fetch from "node-fetch";
import Ajv from "ajv";
import addFormats from "ajv-formats";
dotenv.config();

const w3sClient = new Web3Storage({ token: process.env.W3S_TOKEN as string });
//https://testnets.opensea.io/assets/goerli/0xaf7358576C9F7cD84696D28702fC5ADe33cce0e9/73
const ipnftMetadataUri =
"ipfs://bafkreicnc6ilzauc5e5dhyakk3e6bx3gsre7qtp4nq3b3utjv4fr4oa5f4";

//https://w3s.link/ipfs/bafybeifyciqacag3wev63lspuvxs3e6fe3n6mt4rwharttxgwpkcq6f5z4/ipnft.schema.json
const ipnftSchema001Cid =
"bafkreidvntjwclitnjnk25qe6gcjxqgjthfm5ilx7rsotrnh2k2tooeara";

//https://testnets.opensea.io/assets/goerli/0x36444254795ce6E748cf0317EEE4c4271325D92A/10
const ipnftMetadataArLink = "ar://adXUYrXpfRb6JCYZVrXWxqH3v7zeB25geQvC9e6rmN0";

async function retrieveFromIpfs(cid: string): Promise<string> {
const res = await w3sClient.get(cid);
for await (const entry of res!.unixFsIterator()) {
for await (const chunk of entry.content()) {
return new TextDecoder().decode(chunk);
}
}
throw "not found";
}

async function retrieveFromArweave(arLink: string) {
const arGatewayUrl = arLink.replace("ar://", "https://arweave.net/");
return await (await fetch(arGatewayUrl)).json();
async function retrieveFromIpfs(ipfsLink: string): Promise<any> {
const ipfsGatewayUrl = ipfsLink.replace("ipfs://", "https://ipfs.io/ipfs/");
const content = await fetch(ipfsGatewayUrl);
return content.json();
}

(async () => {
const ipnftSchema = JSON.parse(await retrieveFromIpfs(ipnftSchema001Cid));
const document = await retrieveFromArweave(ipnftMetadataArLink);
const ipnftSchema = await retrieveFromIpfs(
"ipfs://bafybeihvql52zxnkksedcad5i6ptimpquu4oiek56ojldkm3ndkfoevmf4/ipnft.schema.json"
);

const document = await retrieveFromIpfs(ipnftMetadataUri);

const ajv = new Ajv();
addFormats(ajv);
Expand Down
Loading

0 comments on commit 99683e8

Please sign in to comment.