@vocdoni/data-models
v1.15.4-csp
Published
JavaScript/TypeScript models package
Downloads
17
Keywords
Readme
@vocdoni/data-models
@vocdoni/data-models contains the data model definitions for the dvote-js library
Installation
Use npm to install @vocdoni/data-models.
npm install @vocdoni/data-models
Usage
Account Backup
import { AccountBackup } from "@vocdoni/data-models"
const wallet = Wallet.createRandom()
const originalPassphrase = Math.random().toString()
const encryptedMnemonic = AccountBackup.encryptPayload(wallet.mnemonic.phrase, originalPassphrase)
const backupBytes = AccountBackup.create({
backupName: "Hello world",
questionIds: [1, 2, 3],
answers: ["Answer 1", "Answer 2", "Answer 3"],
accountWallet: {
encryptedMnemonic,
authMethod: Wallet_AuthMethod.PASS,
hdPath: wallet.mnemonic.path,
locale: wallet.mnemonic.locale
},
currentPassphrase: originalPassphrase
})
const decryptedPassphrase = AccountBackup.recoverPassphrase(backupBytes, ["Answer 1", "Answer 2", "Answer 3"])
Entity Metadata
import { checkValidEntityMetadata } from "@vocdoni/data-models"
checkValidEntityMetadata({})
// throws an Error
Process Metadata
import { checkValidProcessMetadata } from "@vocdoni/data-models"
checkValidProcessMetadata({})
// throws an Error
Raw transactions
import { Tx, wrapRawTransaction } from "@vocdoni/data-models"
import { BytesSignature } from "@vocdoni/signing"
const tx = Tx.encode(...)
const txBytes = tx.finish()
const signature = await BytesSignature.signTransaction(txBytes, chainId, signer)
const result = wrapRawTransaction(txBytes, signature)
// { method: "submitRawTx", payload: "base64..."}
Testing
To execute library tests just run
npm run test