mui-metablockchain-sdk v3.0.1
MUI Metablockchain SDK
JS SDK to interface with MetaMUI Metablockchain node.
Install
npm install mui-metablockchain-sdkUsage
Network options
The best practice is to first create a websocket connection to the network you intend to connect with and then
pass this object to all function calls.
The available network options are local, dev, testnet, mainnet
If no network is specified, the functions default to either dev or local.
In future when multiple nodes are being hosted, the user will have to option to pass url of the node itself.
Example
- Create a DID and write on chain
const { connection, did, config } = require('mui-metablockchain-sdk');
const NETWORK = "dev";
async function create_new_did(){
const mnemonic = "//Bob";
const new_did = "sample";
// create the DID object
let did_obj = await did.generateDID(mnemonic, new_did, "");
//Use the validator account to sign did operation
const keyring = await config.initKeyring();
const sig_key_pair = await keyring.addFromUri('//Alice');
let provider = await connection.buildConnection(NETWORK);
let tx_hash = await did.storeDIDOnChain(did_obj, sig_key_pair, provider);
return tx_hash;
}Test
npm testModules
- Connection
- Balance
- Collective
- DID
- token
- Transactions
- VC
- Utils
- Schema
- SSID VC
Connection Utilities
Functions
buildConnection(network, ignoreCache)
Return an APIPromise object
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| network | String | local | MetaMUI network provider to connect |
| ignoreCache | Boolen | false | (optional) (default=true) Note : setting the ignoreCache value to true will create a new ws ws conection on every call |
Balance Utilities
Functions
getBalance(did, api) ⇒ String
Get account balance(Highest Form) based on the did supplied.
Kind: global function
Returns: String - Balance In Highest Form
| Param | Type | Default | Description |
|---|---|---|---|
| did | String | Identifier of the user | |
| api | ApiPromse | false | Api Object from Build Connection |
Example
await getBalanceFromDID(did, api)subscribeToBalanceChanges(identifier, callback, api)
Listen to balance changes for a DID and execute the callback.
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| identifier | String | DID | |
| callback | function | Cb function to execute with new balance in Highest Form | |
| api | ApiPromise | false | Api Object from Build Connection |
Collective Utilities
Functions
setMembers(newMembers, prime, oldCount, signingKeypair) ⇒ String
Set Members and prime of collective pallet
Kind: global function
Returns: String - Hash
| Param | Type | Description |
|---|---|---|
| newMembers | Array.<String> | Array of Did |
| prime | String | Did of Prime |
| oldCount | Number | Old members count |
| signingKeypair | KeyPair | Key pair of Sender |
propose(threshold, proposal, lengthCount, signingKeypair)
To create a proposal
Kind: global function
| Param | Type | Description |
|---|---|---|
| threshold | Number | Threshold to successfull execution |
| proposal | Call | Call to propose |
| lengthCount | Number | Length of call |
| signingKeypair | KeyPair | Key pair of sender |
execute(proposal, lengthCount, signingKeypair)
To Execute a call
Kind: global function
| Param | Type | Description |
|---|---|---|
| proposal | Call | Call to propose |
| lengthCount | Number | Length of Call |
| signingKeypair | KeyPair | Key pair of sender |
vote(proposalHash, index, approve, signingKeypair)
Vote on a proposal
Kind: global function
| Param | Type | Description |
|---|---|---|
| proposalHash | String | Hash of proposal |
| index | Number | Proposal index |
| approve | Boolean | True/false |
| signingKeypair | KeyPair | Key pair of sender |
close(proposalHash, index, proposalWeightBond, lengthCount, signingKeypair)
Close a proposal manually, executes call if yes votes is greater than or equal to threshold
Kind: global function
| Param | Type | Description |
|---|---|---|
| proposalHash | String | Hash |
| index | Number | Proposal index |
| proposalWeightBond | Boolean | Weight |
| lengthCount | Number | Length |
| signingKeypair | KeyPair | Key pair of sender |
disapproveProposal(proposalHash, signingKeypair)
Disapprove proposal
Kind: global function
| Param | Type | Description |
|---|---|---|
| proposalHash | String | Hash |
| signingKeypair | KeyPair | Key pair of sender |
getMembers(api)
Get Members of Council
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| api | Boolean | false | Network Provider |
getPrime(api)
Get Prime of Council
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| api | Boolean | false | Network Provider |
getProposals(api)
Get All Proposals
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| api | Boolean | false | Network Provider |
getProposalOf(proposalHash, api)
Get Proposal of given hash
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| proposalHash | Hash | Hash of proposal | |
| api | Boolean | false | Network Provider |
getVotes(proposalHash, api)
Get Votes of given proposal hash
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| proposalHash | Hash | Hash of proposal | |
| api | Boolean | false | Network Provider |
getProposalCount(api)
Get Total proposals count
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| api | Boolean | false | Network Provider |
DID Utilties
Functions
generateMnemonic() ⇒ String
Generate Mnemonic
Kind: global function
Returns: String - Mnemonic
storeDIDOnChain(params, api) ⇒ String
Stores the generated DID object on the blockchain.
Kind: global function
Returns: String - The transaction ID for the storage operation.
| Param | Type | Description |
|---|---|---|
| params | Object | The params object. |
| params.didDetails | Object | DID object to be stored, generated using generateDID function. |
| params.signingKeypair | Object | The keypair used for signing the transaction. |
| params.appId | String | The optional application ID. |
| api | ApiPromise | The API object for blockchain interaction. |
updateDidKey(params, api) ⇒ Promise.<void>
Rotates the keys assigned to a DID. This operation should only be called by validator accounts, otherwise it will fail.
Kind: global function
Returns: Promise.<void> - A promise that resolves once the operation is completed.
| Param | Type | Description |
|---|---|---|
| params | Object | The params object. |
| params.identifier | String | The identifier of the DID. |
| params.newKey | Uint8Array | HexString | The new key to be assigned to the DID. |
| params.signingKeypair | Keyring | The keypair of a validator account for signing the transaction. |
| params.appId | String | The optional application ID. |
| api | ApiPromise | The API object for blockchain interaction. |
addPublicKey(vcHex, signingKeypair, api) ⇒ Promise.<String>
Store the generated DID object in blockchain
Kind: global function
Returns: Promise.<String> - Promise that resolves to txnId for storage operation.
| Param | Type | Default | Description |
|---|---|---|---|
| vcHex | String | VC Hex String | |
| signingKeypair | KeyPair | Owner Key Ring pair | |
| api | ApiPromise | false | (optional) |
updateMetadata(identifier, metadata, signingKeypair, api) ⇒ Promise.<String>
Kind: global function
Returns: Promise.<String> - Promise that resolves to txnId for storage operation.
| Param | Type | Default | Description |
|---|---|---|---|
| identifier | String | ||
| metadata | String | ||
| signingKeypair | KeyringObj | of a validator account | |
| api | ApiPromise | false |
getDIDDetails(identifier) ⇒ JSON
Get did information from accountID
Kind: global function
| Param | Type | Description |
|---|---|---|
| identifier | String | DID Identifier |
didLookup(identifier) ⇒ JSON
Get did information from Did
Kind: global function
| Param | Type | Description |
|---|---|---|
| identifier | String | DID Identifier |
didLookupByApp(params, api) ⇒ JSON
Get did information from Did
Kind: global function
| Param | Type | Description |
|---|---|---|
| params | Object | The params object. |
| params.identifier | String | DID Identifier |
| params.appId | String | Application ID |
| api | ApiPromise | The API connection to use, defaults to a local connection |
getBlockNumber(params, api) ⇒ Promise.<String>
Get the block number for a given DID
Kind: global function
Returns: Promise.<String> - - The block number associated with the given DID
| Param | Type | Description |
|---|---|---|
| params | Object | The params object |
| params.identifier | String | The DID identifier to resolve |
| params.appId | String | The application ID to use for the lookup, defaults to null |
| api | ApiPromise | The API connection to use, defaults to a local connection |
resolveDIDToAccount(params, api) ⇒ String
Get the accountId for a given DID
Kind: global function
Returns: String - - The account ID associated with the given DID
| Param | Type | Description |
|---|---|---|
| params | Object | The params object |
| params.identifier | String | The DID identifier to resolve |
| params.blockNumber | Number | The block number to use for the lookup, defaults to null |
| params.appId | String | The application ID to use for the lookup, defaults to null |
| api | ApiPromise | The API connection to use, defaults to a local connection |
resolveAccountIdToDid(accountId, api) ⇒ String | Boolean
Get the DID associated to given accountID
Kind: global function
Returns: String | Boolean - (false if not found)
| Param | Type | Default | Description |
|---|---|---|---|
| accountId | String | (hex/base64 version works) | |
| api | ApiPromise | false |
getDidPalletVersion(api) ⇒ JSON | null
Get did information from accountID
Kind: global function
Returns: JSON | null - - The pallet version data or null if an error occurs
| Param | Type | Description |
|---|---|---|
| api | ApiPromise | The Polkadot API Promise (optional) |
getPublicKeyByAppId(params, api) ⇒ JSON
Get public key details for a given DID identifier and optional application ID
Kind: global function
Returns: JSON - - The public key details in JSON format
Throws:
- Error - Throws an error if unable to fetch public key details
| Param | Type | Description |
|---|---|---|
| params | Object | The params object |
| params.identifier | String | The DID identifier |
| params.appId | String | The application ID (optional) |
| api | ApiPromise | The API connection to use, defaults to a local connection |
isDidValidator(identifier, api) ⇒ Boolean
Check if the user is an approved validator
Kind: global function
| Param | Type | Default |
|---|---|---|
| identifier | String | |
| api | ApiPromise | false |
getDidKeyHistory(params, api) ⇒ Array
Fetch the history of rotated keys for the specified DID
Kind: global function
Returns: Array - - The key history data
Throws:
- Error - Throws an error if unable to fetch key history
| Param | Type | Description |
|---|---|---|
| params | Object | The params object |
| params.identifier | String | The DID identifier for which to fetch the key history |
| params.appId | String | The application ID, defaults to null |
| api | ApiPromise | The API connection to use, defaults to a local connection |
generateDID(mnemonic, identifier, metadata) ⇒ Object
Generate did object to be stored in blockchain.
Kind: global function
Returns: Object - Object containing did structure
| Param | Type |
|---|---|
| mnemonic | String |
| identifier | String |
| metadata | String |
generateAddKeyVC(params, owner, sigKeypair) ⇒ String
Create VC
Kind: global function
Returns: String - VC Hex String
| Param | Type | Description |
|---|---|---|
| params | Object | |
| params.appId | String | App ID of new public key |
| params.issuerAppid | String | App ID of issuer DID |
| params.newPublicKey | HexString | New Public Key to be added to DID |
| owner | String | DID of the owner |
| sigKeypair | KeyPair | DID Owner Key Ring pair |
sanitiseDid(did) ⇒ String
Checks if the given did is in hex format or not & converts it into valid hex format.
Note: This util function is needed since dependant module wont convert the utf did to hex anymore
Kind: global function
Returns: String - Hex did
| Param | Type |
|---|---|
| did | String |
findRegionFromDid(did)
This function will find the region from the DID
Kind: global function
| Param | Type |
|---|---|
| did | String |
convertFixedSizeHex(data, size) ⇒ String
Convert to hex but return fixed size always, mimics substrate storage
Kind: global function
| Param | Type | Default |
|---|---|---|
| data | String | |
| size | Int | 64 |
Token Utilities
Functions
issueToken(vcId, totalIssuanceAmt, senderAccountKeyPair, api) ⇒ hexString
Issue new token from given vc Id. Amount is in lowest form here but everywhere else it's in highest form
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| vcId | String | ||
| totalIssuanceAmt | String | Amount is in lowest form | |
| senderAccountKeyPair | KeyPair | ||
| api | APIPromise | false |
transferToken(recipentDid, currencyCode, tokenAmount, senderAccountKeyPair, api) ⇒ hexString
Transfer token with given token_id to the recipent_did
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| recipentDid | String | ||
| currencyCode | String | ||
| tokenAmount | String | In Highest Form | |
| senderAccountKeyPair | KeyPair | ||
| api | APIPromise | false |
transferTokenWithMemo(recipentDid, currencyCode, tokenAmount, memo, senderAccountKeyPair, api) ⇒ hexString
Transfer token with given token_id to the recipent_did with an additional memo
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| recipentDid | String | ||
| currencyCode | String | ||
| tokenAmount | String | In Highest Form | |
| memo | String | ||
| senderAccountKeyPair | KeyPair | ||
| api | APIPromise | false |
transferAll(recipentDid, currencyCode, senderAccountKeyPair, api) ⇒ hexString
Transfer all token with given vc_id to the recipent_did
Kind: global function
| Param | Type | Default |
|---|---|---|
| recipentDid | String | |
| currencyCode | String | |
| senderAccountKeyPair | KeyPair | |
| api | APIPromise | false |
slashToken(vcId, senderAccountKeyPair, api) ⇒ hexString
Slash token from given currency
Kind: global function
| Param | Type | Default |
|---|---|---|
| vcId | String | |
| senderAccountKeyPair | KeyPair | |
| api | APIPromise | false |
mintToken(vcId, senderAccountKeyPair, api) ⇒ hexString
Mint token to given currency
Kind: global function
| Param | Type | Default |
|---|---|---|
| vcId | String | |
| senderAccountKeyPair | KeyPair | |
| api | APIPromise | false |
getTokenBalance(did, currencyCode, api) ⇒ String
Get the token balance for a given token for given did
Kind: global function
Returns: String - Balance In Highest Form
| Param | Type | Default |
|---|---|---|
| did | String | |
| currencyCode | String | |
| api | ApiPromise | false |
subscribeToGetTokenBalance(did, currencyCode, callback, api) ⇒ Object
Subscribe to get the detailed token balance for a given token for given did
Kind: global function
Returns: Object - In Highest Form
| Param | Type | Default | Description |
|---|---|---|---|
| did | String | ||
| currencyCode | String | ||
| callback | function | Cb function to execute with new token balance in Highest Form | |
| api | ApiPromise | false |
getDetailedTokenBalance(did, currencyCode, api) ⇒ Object
Get the detailed token balance for a given token for given did
Kind: global function
Returns: Object - In Highest Form
| Param | Type | Default |
|---|---|---|
| did | String | |
| currencyCode | String | |
| api | ApiPromise | false |
subscribeToGetDetailedTokenBalance(did, currencyCode, callback, api) ⇒ Object
Subscribe to get the detailed token balance for a given token for given did
Kind: global function
Returns: Object - In Highest Form
| Param | Type | Default | Description |
|---|---|---|---|
| did | String | ||
| currencyCode | String | ||
| callback | function | Cb function to execute with new token balance in Highest Form | |
| api | ApiPromise | false |
getTokenList(api) ⇒ Array
Get the list of all active tokens in metablockchain network
Kind: global function
Returns: Array - { id: '1', name: 'XYZ' }, { id: '2', name: 'ABC' }
| Param | Type | Default |
|---|---|---|
| api | ApiPromise | false |
getTokenData(currencyCode, api) ⇒ Object
Get the token by currency id in metablockchain network
Kind: global function
| Param | Type | Default |
|---|---|---|
| currencyCode | String | |
| api | ApiPromise | false |
getTokenTotalSupply(currencyCode, api) ⇒ String
Get the total issuance amount for given currency id
Kind: global function
Returns: String - TotalSupply In Highest Form
| Param | Type | Default |
|---|---|---|
| currencyCode | String | |
| api | ApiPromise | false |
getLocks(currencyCode, api) ⇒ Object
Get the lock for given currency id
Kind: global function
| Param | Type | Default |
|---|---|---|
| currencyCode | String | |
| api | ApiPromise | false |
getTokenIssuer(currencyCode, api) ⇒ String
Get the issuer for given token code
Kind: global function
| Param | Type | Default |
|---|---|---|
| currencyCode | String | |
| api | ApiPromise | false |
withdrawTreasuryReserve(destination, from, amount, senderAccountKeyPair, api) ⇒ String
Function to withdraw the treasury reserve amount locked at the time of token creation. Only a validator can call this operation succesfully.
Kind: global function
Returns: String - transaction_hex_id
| Param | Type | Default | Description |
|---|---|---|---|
| destination | String | (DID) | |
| from | String | (DID) | |
| amount | String | (MUI amount) | |
| senderAccountKeyPair | KeyPair | ||
| api | ApiPromise | false |
transferTokenWithVC(vcId, receiverDID, senderAccountKeyPair, api) ⇒ hexString
Transfer token of given currency to given Did from Currency owner account
Kind: global function
| Param | Type | Default |
|---|---|---|
| vcId | String | |
| receiverDID | String | |
| senderAccountKeyPair | KeyPair | |
| api | APIPromise | false |
setBalance(dest, currencyCode, amount, senderAccountKeyPair, api) ⇒ hexString
Set balance of did with given token_id Can be called only token owner
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| dest | String | ||
| currencyCode | String | ||
| amount | String | In Highest Form | |
| senderAccountKeyPair | KeyPair | ||
| api | APIPromise | false |
sanitiseCCode(currency_code) ⇒ String
Checks if the given currency_code is in hex format or not & converts it into valid hex format.
Note: This util function is needed since dependant module wont convert the utf did to hex anymore
Kind: global function
Returns: String - Hex currency_code
| Param | Type |
|---|---|
| currency_code | String |
getFormattedTokenAmount(currency_code, tokenAmount, provider) ⇒ Number
Formats the given amount into lowest form based on the decimals supported by given token.
Kind: global function
Returns: Number - tokenAmount in lowest form else error
| Param | Type | Description |
|---|---|---|
| currency_code | String | in the sanitised form |
| tokenAmount | String | in the highest form |
| provider | APIPromise |
removeToken(currencyCode, vcId, clearAccounts, signingKeypair, identity) ⇒ String
Remove token
Kind: global function
Returns: String - Hash
| Param | Type | Default |
|---|---|---|
| currencyCode | String | |
| vcId | String | |
| clearAccounts | Bool | |
| signingKeypair | KeyPair | |
| identity | String |
Transaction Utilities
Functions
sendTransaction(senderAccountKeyPair, receiverDID, amount, api, nonce) ⇒ Uint8Array
The function will perform a metamui transfer operation from the account of senderAccount to the receiverDID. Note : balanceCheck has not been included in the checks since sender not having balance is handled in extrinsic, check test/transaction.js
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| senderAccountKeyPair | KeyPair | ||
| receiverDID | String | ||
| amount | String | In Lowest Form | |
| api | APIPromise | false | (optional) |
| nonce | int | (optional) |
transfer(senderAccountKeyPair, receiverDID, amount, memo, api, nonce) ⇒ Uint8Array
This function is similar to sendTransaction except that it provides the user to add the memo to transfer functionality.
Kind: global function
| Param | Type | Default | Description |
|---|---|---|---|
| senderAccountKeyPair | KeyPair | ||
| receiverDID | String | ||
| amount | String | In Lowest Form | |
| memo | String | ||
| api | APIPromise | false | (optional) |
| nonce | int | (optional) |
Verifiable Credential (VC) Utilities
Functions
createTokenVC(TokenVC) ⇒ String
Encodes Token VC and pads with appropriate bytes
Kind: global function
Returns: String - Token VC Hex String
| Param | Type | Description |
|---|---|---|
| TokenVC | Object | |
| TokenVC.tokenName | String | |
| TokenVC.reservableBalance | String | In Highest Form |
| TokenVC.decimal | String | |
| TokenVC.currencyCode | String |
createMintSlashVC(vcProperty) ⇒ String
Encodes Token VC and pads with appropriate bytes
Kind: global function
Returns: String - Token VC Hex String
| Param | Type | Description |
|---|---|---|
| vcProperty | Object | |
| vcProperty.vcId | String | |
| vcProperty.currencyCode | String | |
| vcProperty.amount | String | In Highest Form |
createTokenTransferVC(vcProperty) ⇒ String
Encodes Token VC and pads with appropriate bytes
Kind: global function
Returns: String - Token VC Hex String
| Param | Type | Description |
|---|---|---|
| vcProperty | Object | |
| vcProperty.vcId | String | |
| vcProperty.currencyCode | String | |
| vcProperty.amount | String | In Highest Form |
createGenericVC(vcProperty) ⇒ String
Encodes Generic VC and pads with appropriate bytes
Kind: global function
Returns: String - Token VC Hex String
| Param | Type |
|---|---|
| vcProperty | Object |
| vcProperty.cid | String |
generateVC(vcProperty, owner, issuers, vcType, sigKeypair) ⇒ String
Create VC
Kind: global function
Returns: String - VC Hex String
| Param | Type | Description |
|---|---|---|
| vcProperty | Object | |
| owner | String | Did |
| issuers | Array.<String> | Array of Did |
| vcType | String | TokenVC, MintTokens, SlashTokens, TokenTransferVC, GenericVC |
| sigKeypair | KeyPair | Owner Key Ring pair |
approveVC(vcID, signingKeyPair, api) ⇒ String
Approve VC
Kind: global function
Returns: String - Transaction hash or Error
| Param | Type | Description |
|---|---|---|
| vcID | Object | vc_id of VC to be approved |
| signingKeyPair | KeyPair | Issuer Key Ring pair |
| api | APIPromise |
storeVC(vcHex, senderAccountKeyPair, api) ⇒ hexString
Store vc hex
Kind: global function
| Param | Type | Default |
|---|---|---|
| vcHex | String | |
| senderAccountKeyPair | KeyPair | |
| api | APIPromise | false |
updateStatus(vcId, vcStatus, senderAccountKeyPair, api) ⇒ hexString
Update Status
Kind: global function
| Param | Type | Default |
|---|---|---|
| vcId | String | |
| vcStatus | String | |
| senderAccountKeyPair | KeyPair | |
| api | APIPromise | false |
getVCs(vcId, api) ⇒ String
Get VCs by VC id
Kind: global function
Returns: String - (false if not found)
| Param | Type | Default | Description |
|---|---|---|---|
| vcId | String | (hex/base64 version works) | |
| api | ApiPromise | false |
getVCIdsByDID(did, api) ⇒ String
Get VC Ids by did
Kind: global function
Returns: String - (false if not found)
| Param | Type | Default | Description |
|---|---|---|---|
| did | String | (hex/base64 version works) | |
| api | ApiPromise | false |
getDIDByVCId(vcId, api) ⇒ String
Get DID by VC Id
Kind: global function
Returns: String - (false if not found)
| Param | Type | Default | Description |
|---|---|---|---|
| vcId | String | (hex/base64 version works) | |
| api | ApiPromise | false |
getVCHistoryByVCId(vcId, api) ⇒ String
Get VC history by VC Id
Kind: global function
Returns: String - (false if not found)
| Param | Type | Default | Description |
|---|---|---|---|
| vcId | String | (hex/base64 version works) | |
| api | ApiPromise | false |
getVCApprovers(vcId, api) ⇒ Array.<Did>
Get approved issuers of the VC
Kind: global function
Returns: Array.<Did> - approved issuer list
| Param | Type | Default | Description |
|---|---|---|---|
| vcId | String | (hex/base64 version works) | |
| api | ApiPromise | false |
getGenericVCDataByCId(vcId, api) ⇒ JSON
Get Generic vc data
Kind: global function
Returns: JSON - Generic VC data
| Param | Type |
|---|---|
| vcId | String |
| api | ApiPromise |
getGenericVCData(vcId, api) ⇒ JSON
Get Generic vc data
Kind: global function
Returns: JSON - Generic VC data
| Param | Type | Default |
|---|---|---|
| vcId | String | |
| api | ApiPromise | false |
verifyGenericVC(vcId, data, api) ⇒ Boolean
Verify Generic Vc data
Kind: global function
Returns: Boolean - true if verified
| Param | Type | Default |
|---|---|---|
| vcId | String | |
| data | Object | |
| api | ApiPromise | false |
createVC(properties_json, schema_hash) ⇒ JSON
The function returns the VC in the expected format, the verifier and signature fields are left blank to be filled by signing function
Kind: global function
| Param | Type |
|---|---|
| properties_json | JSON |
| schema_hash | Hex |
signVC(vcJson, verifierDid, signingKeyPair) ⇒ JSON
Sign a VC using the given verifier_pvkey
Kind: global function
| Param | Type |
|---|---|
| vcJson | JSON |
| verifierDid | String |
| signingKeyPair | KeyPair |
verifyVC(vcJson) ⇒ Boolean
Verify if the signature/verifier DID is valid and matches the given data in vc_json
Kind: global function
Returns: Boolean - true if valid VC
| Param | Type |
|---|---|
| vcJson | JSON |
Other Utilities
Functions
bytesToHex(inputBytes)
Kind: global function
| Param | Type | Description |
|---|---|---|
| inputBytes | Bytes | u8[] |
hexToBytes(inputString)
Kind: global function
| Param | Type |
|---|---|
| inputString | String |
base58ToBytes(bs58string)
Kind: global function
| Param | Type |
|---|---|
| bs58string | Base58 |
stringToBytes(inputString)
Kind: global function
| Param | Type |
|---|---|
| inputString | String |
hexToString(hexString)
Kind: global function
| Param | Type |
|---|---|
| hexString | Hex |
vcHexToVcId(hexString)
Kind: global function
| Param | Type |
|---|---|
| hexString | Hex |
encodeData(data, typeKey) ⇒ String
Encodes object/ string of given type to hex
Kind: global function
Returns: String - Encoded Hex
| Param | Type | Description |
|---|---|---|
| data | Object | String | Object to be encoded |
| typeKey | String | Key from METABLOCKCHAIN_TYPES which represents type of data |
decodeHex(hexValue, typeKey) ⇒ Object | String
Decodes hex of given type to it's corresponding object/value
Kind: global function
Returns: Object | String - Decoded Object/String
| Param | Type | Description |
|---|---|---|
| hexValue | String | Hex String to be decoded |
| typeKey | String | Key from METABLOCKCHAIN_TYPES which represents type of data |
isUpperAndValid(str) ⇒
Checks if str is upper and only contains characters
Kind: global function
Returns: bool
| Param |
|---|
| str |
tidy(s) ⇒ Object | String
regex to remove unwanted hex bytes
Kind: global function
Returns: Object | String - Decoded tidy Object/String
| Param | Type | Description |
|---|---|---|
| s | String | Hex String to make tidy |
getVCS(hexValue, typeKey) ⇒ Object | String
function that decodes hex of createTokenVC
Kind: global function
Returns: Object | String - Decoded Object/String
| Param | Type | Description |
|---|---|---|
| hexValue | String | Hex String to be decoded |
| typeKey | String | Key from METABLOCKCHAIN_TYPES which represents type of data |
decodeVC(hexValue, typeKey) ⇒ Object | String
function that decodes hex of createVC where type is TokenVC to it's corresponding object/value
Kind: global function
Returns: Object | String - Decoded Object/String
| Param | Type | Description |
|---|---|---|
| hexValue | String | Hex String to be decoded |
| typeKey | String | Key from METABLOCKCHAIN_TYPES which represents type of data |
sortObjectByKeys(unorderedObj) ⇒ Object
Sort object by keys
Kind: global function
Returns: Object - ordered object by key
| Param | Type | Description |
|---|---|---|
| unorderedObj | Object | unordered object |
generateObjectHash(unordered) ⇒ Object
generate blake hash of js object
Kind: global function
Returns: Object - ordered object by key
| Param | Type | Description |
|---|---|---|
| unordered | Object | unordered object |
Schema
Functions
createNewSchema(schema_properties) ⇒ JSON
Create a new schema with the properties provided in the schema_properties json The stringified schema and its hash will be returned as required by the extrinsic.
Kind: global function
| Param | Type |
|---|---|
| schema_properties | JSON |
storeSchemaOnChain(schema, signingKeypair)
Write a new schema to the chain using the account provided This extrinsic can only be called by the accounts in the validator_set pallet
Kind: global function
| Param | Type |
|---|---|
| schema | JSON |
| signingKeypair | String |
doesSchemaExist(schemaHash) ⇒ Boolean
The function will returns the Boolean value based on valid/invalid schemaHash.
Kind: global function
Returns: Boolean - Will return true, if valid schemaHash
| Param | Type |
|---|---|
| schemaHash | Hex |
SSID VC
Functions
createSsidVC(properties_json) ⇒ JSON
The function returns the VC in the expected format, the signature field is left blank to be filled by signing function
Kind: global function
| Param | Type |
|---|---|
| properties_json | JSON |
signSsidVC(vcJson, signerKeyPair) ⇒ JSON
Sign a VC using the given verifier_pvkey
Kind: global function
| Param | Type |
|---|---|
| vcJson | JSON |
| signerKeyPair | KeyPair |
verifySsidVC(vcJson) ⇒ Boolean
Verify if the signature is valid and matches the given public_key in ssid_vc
Kind: global function
Returns: Boolean - true if valid SSID_VC
| Param | Type |
|---|---|
| vcJson | JSON |