Skip to content

Instantly share code, notes, and snippets.

@xpepermint
Last active October 10, 2021 17:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xpepermint/5e69e2654aaa78035db4e3c26cbbab0e to your computer and use it in GitHub Desktop.
Save xpepermint/5e69e2654aaa78035db4e3c26cbbab0e to your computer and use it in GitHub Desktop.
0xcert.org certification
const { Cert } = require('@0xcert/cert');
const { HttpProvider } = require('@0xcert/ethereum-http-provider');
const { AssetLedger } = require('@0xcert/ethereum-asset-ledger');
(async () => {
const schema = {
"$schema": "http://json-schema.org/draft-07/schema",
"description": "A digital assets that have a unique combination of different properties.",
"properties": {
"$evidence": {
"description": "A URI pointing to the evidence JSON with data needed to certify this asset.",
"type": "string"
},
"$schema": {
"description": "A path to JSON Schema definition file.",
"type": "string"
},
"description": {
"description": "A property that holds a detailed description of an asset.",
"type": "string"
},
"image": {
"description": "A public property that can be a valid URI pointing to a resource with mime type image/* representing the asset to which this digital assets represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive.",
"type": "string"
},
"name": {
"description": "A property that holds a name of an asset.",
"type": "string"
}
},
"required": ["$schema", "description", "image", "name"],
"title": "Crypto collectible asset",
"type": "object"
};
console.log('Schema:', JSON.stringify(schema), '\n');
const metadata = {
"$evidence": "https://troopersgame.com/dog/evidence.json",
"$schema": "https://conventions.0xcert.org/88-crypto-collectible-schema.json",
"name": "Magic Sword",
"description": "A weapon for the Troopers game which can severely injure the enemy.",
"image": "https://troopersgame.com/dog.jpg"
};
console.log('Metadata:', JSON.stringify(metadata), '\n');
const cert = new Cert({
schema,
});
const schemaId = await cert.identify();
console.log('Schema ID:', JSON.stringify(schemaId), '\n');
const evidence = await cert.notarize(metadata);
console.log('Evidence:', JSON.stringify(evidence), '\n');
const imprint = await cert.imprint(metadata);
console.log('Imprint:', JSON.stringify(imprint), '\n');
const assetId = 100;
console.log('Asset ID:', JSON.stringify(assetId), '\n');
const exposedMetadata = cert.expose(metadata, [
['name'],
]);
console.log('Exposed metadata:', JSON.stringify(exposedMetadata), '\n');
const exposedEvidence = await cert.disclose(metadata, [
['name'],
]);
console.log('Exposed evidence:', JSON.stringify(exposedEvidence), '\n');
const ledgerId = '0x598B4D17573407D1999C29A84A317F17689a0535';
console.log('Ledger ID:', JSON.stringify(ledgerId), '\n');
const provider = new HttpProvider({
url: 'https://ropsten.infura.io/v3/a491d5932d4d47b58f4ba2e043278ac4',
});
const ledger = new AssetLedger(provider, ledgerId);
const ledgerInfo = await ledger.getInfo();
console.log('Ledger info:', JSON.stringify(ledgerInfo), '\n');
const assetInfo = await ledger.getAsset(assetId);
console.log('Asset info:', JSON.stringify(assetInfo), '\n');
const assetVerified = await cert.calculate(exposedMetadata, exposedEvidence);
console.log('Asset verified:', JSON.stringify(assetVerified === assetInfo.imprint), '\n');
})();
const { Cert } = require('@0xcert/cert');
const { HttpProvider } = require('@0xcert/wanchain-http-provider');
const { AssetLedger } = require('@0xcert/wanchain-asset-ledger');
(async () => {
const schema = {
"$schema": "http://json-schema.org/draft-07/schema",
"description": "A digital assets that have a unique combination of different properties.",
"properties": {
"$evidence": {
"description": "A URI pointing to the evidence JSON with data needed to certify this asset.",
"type": "string"
},
"$schema": {
"description": "A path to JSON Schema definition file.",
"type": "string"
},
"description": {
"description": "A property that holds a detailed description of an asset.",
"type": "string"
},
"image": {
"description": "A public property that can be a valid URI pointing to a resource with mime type image/* representing the asset to which this digital assets represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive.",
"type": "string"
},
"name": {
"description": "A property that holds a name of an asset.",
"type": "string"
}
},
"required": ["$schema", "description", "image", "name"],
"title": "Crypto collectible asset",
"type": "object"
};
console.log('Schema:', JSON.stringify(schema), '\n');
const metadata = {
"$evidence": "https://troopersgame.com/dog/evidence.json",
"$schema": "https://conventions.0xcert.org/88-crypto-collectible-schema.json",
"name": "Magic Sword",
"description": "A weapon for the Troopers game which can severely injure the enemy.",
"image": "https://troopersgame.com/dog.jpg"
};
console.log('Metadata:', JSON.stringify(metadata), '\n');
const cert = new Cert({
schema,
});
const schemaId = await cert.identify();
console.log('Schema ID:', JSON.stringify(schemaId), '\n');
const evidence = await cert.notarize(metadata);
console.log('Evidence:', JSON.stringify(evidence), '\n');
const imprint = await cert.imprint(metadata);
console.log('Imprint:', JSON.stringify(imprint), '\n');
const assetId = 100;
console.log('Asset ID:', JSON.stringify(assetId), '\n');
const exposedMetadata = cert.expose(metadata, [
['name'],
]);
console.log('Exposed metadata:', JSON.stringify(exposedMetadata), '\n');
const exposedEvidence = await cert.disclose(metadata, [
['name'],
]);
console.log('Exposed evidence:', JSON.stringify(exposedEvidence), '\n');
const ledgerId = '0xAf625CAa3a303B01227FBD262B4Dac833b414263';
console.log('Ledger ID:', JSON.stringify(ledgerId), '\n');
const provider = new HttpProvider({
url: 'https://gwan-ssl.wandevs.org:46891/',
});
const ledger = new AssetLedger(provider, ledgerId);
const ledgerInfo = await ledger.getInfo();
console.log('Ledger info:', JSON.stringify(ledgerInfo), '\n');
const assetInfo = await ledger.getAsset(assetId);
console.log('Asset info:', JSON.stringify(assetInfo), '\n');
const assetVerified = await cert.calculate(exposedMetadata, exposedEvidence);
console.log('Asset verified:', JSON.stringify(assetVerified === assetInfo.imprint), '\n');
})();
const { Cert } = require('@0xcert/cert');
(async () => {
const schema = {
"$schema": "http://json-schema.org/draft-07/schema",
"description": "A digital assets that have a unique combination of different properties.",
"properties": {
"$evidence": {
"description": "A URI pointing to the evidence JSON with data needed to certify this asset.",
"type": "string"
},
"$schema": {
"description": "A path to JSON Schema definition file.",
"type": "string"
},
"description": {
"description": "A property that holds a detailed description of an asset.",
"type": "string"
},
"image": {
"description": "A public property that can be a valid URI pointing to a resource with mime type image/* representing the asset to which this digital assets represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive.",
"type": "string"
},
"name": {
"description": "A property that holds a name of an asset.",
"type": "string"
}
},
"required": ["$schema", "description", "image", "name"],
"title": "Crypto collectible asset",
"type": "object"
};
console.log('Schema:', JSON.stringify(schema), '\n');
const metadata = {
"$evidence": "https://troopersgame.com/dog/evidence.json",
"$schema": "https://conventions.0xcert.org/88-crypto-collectible-schema.json",
"name": "Magic Sword",
"description": "A weapon for the Troopers game which can severely injure the enemy.",
"image": "https://troopersgame.com/dog.jpg"
};
console.log('Metadata:', JSON.stringify(metadata), '\n');
const cert = new Cert({
schema,
});
const schemaId = await cert.identify();
console.log('Schema ID:', JSON.stringify(schemaId), '\n');
const evidence = await cert.notarize(metadata);
console.log('Evidence:', JSON.stringify(evidence), '\n');
const imprint = await cert.imprint(metadata);
console.log('Imprint:', JSON.stringify(imprint), '\n');
const assetId = 100;
console.log('Asset ID:', JSON.stringify(assetId), '\n');
const exposedMetadata = cert.expose(metadata, [
['name'],
]);
console.log('Exposed metadata:', JSON.stringify(exposedMetadata), '\n');
const exposedEvidence = await cert.disclose(metadata, [
['name'],
]);
console.log('Exposed evidence:', JSON.stringify(exposedEvidence), '\n');
const exposedVerified = await cert.calculate(exposedMetadata, exposedEvidence);
console.log('Exposed verified:', JSON.stringify(exposedVerified === imprint), '\n');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment