Skip to content

Commit

Permalink
add helper function building assetEntryUri(temporary)
Browse files Browse the repository at this point in the history
Signed-off-by: Shreevatsa N <[email protected]>
  • Loading branch information
vatsa287 committed Mar 26, 2024
1 parent ca9fb95 commit f7855b6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
6 changes: 3 additions & 3 deletions demo/res/asset_vc_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"$metadata": {
"version": "1.0.0",
"slug": "test-demo-schema",
"slug": "asset-demo-schema",
"discoverable": true
},
"title": "Test Demo Schema v3",
"description": "Test Demo Schema",
"title": "Asset Demo Schema v3",
"description": "Asset Demo Schema",
"properties": {
"assetType": {
"type": "string"
Expand Down
61 changes: 57 additions & 4 deletions demo/src/asset-vc-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,63 @@ import { addNetworkMember } from "./utils/createAuthorities.js";
import { createAccount } from "./utils/createAccount.js";

import * as vcExport from "@cord.network/vc-export";

import { uriToIdentifier } from '@cord.network/identifier'

import { createDid } from "./utils/generateDid";
import PalletAssetVcAssetEntry from '@polkadot/types/lookup';

const { NETWORK_ADDRESS, ANCHOR_URI } = process.env;

/* TODO: Remove unused below dependencies after AssetEntryUri is built in vcExport library */
import { hashToUri, uriToIdentifier } from '@cord.network/identifier'
import {
IAssetProperties,
ASSET_IDENT,
ASSET_PREFIX,
AssetUri,
IAssetIssuance,
ASSET_INSTANCE_IDENT,
IAssetTransfer,
IAssetEntry,
IAssetTransferEntry,
DidUri,
SpaceUri,
blake2AsHex,
AccountId,
H256,
Bytes,
} from '@cord.network/types'
import { Crypto } from '@cord.network/utils'
import * as Did from '@cord.network/did'
//import AccountId32 from '@polkadot/types/interfaces/runtime';


/* TODO: Take arguments, generate digests with typed arguments */
async function buildAssetUri(assetInput: IAssetEntry, issuerUri: DidUri , spaceUri: SpaceUri, api: any) {
//const api = Cord.ConfigService.get("api");
const entryDigest = Crypto.hashObjectAsHexStr(assetInput);

const scaleEncodedAssetDigest = api
.createType("H256", entryDigest)
.toU8a();
const scaleEncodedIssuer = api
.createType('AccountId', Did.toChain(issuerUri))
.toU8a()
const scaleEncodedSpace = api
.createType('Bytes', uriToIdentifier(spaceUri))
.toU8a()

const assetIdDigest = blake2AsHex(
Uint8Array.from([...scaleEncodedAssetDigest, ...scaleEncodedSpace, ...scaleEncodedIssuer])
);

const assetIdentifier = hashToUri(
assetIdDigest,
ASSET_IDENT,
ASSET_PREFIX
) as AssetUri;

return assetIdentifier
}

async function main() {
const networkAddress = NETWORK_ADDRESS ?? 'ws://127.0.0.1:60477';
const anchorUri = ANCHOR_URI ?? '//Alice';
Expand Down Expand Up @@ -188,6 +237,9 @@ async function main() {
authorizationId: uriToIdentifier(space.authorization),
}});

/* TODO: Build assetEntryUri from vcExport library */
const assetEntryUri = await buildAssetUri(assetProperties, issuerDid.uri, space.uri, api);

const extrinsic = await Cord.Asset.dispatchCreateVcToChain(
assetProperties.assetQty,
vc.credentialHash,
Expand All @@ -205,7 +257,8 @@ async function main() {
// Step 3: Issue Asset to Holder
console.log(`\n❄️ Issue Asset to Holder - Issuer Action `);
const assetIssuance = await Cord.Asset.buildFromIssueProperties(
assetEntry.uri,
//assetEntry.uri,
assetEntryUri,
holderDid.uri,
1,
issuerDid.uri,
Expand Down

0 comments on commit f7855b6

Please sign in to comment.