⚠️ Under active development⚠️
Crypto operations for Vega supporting Node.js and Browsers
This module supports both CommonJS and ES Modules:
const { VegaWallet, HARDENED } = require('@vegaprotocol/crypto')
VegaWallet.fromMnemonic('...').then(async wallet => {
const keys = await wallet.keyPair(HARDENED + 0)
const msg = Buffer.from('Hello world!')
const signature = await keys.sign(msg)
})
import { VegaWallet, HARDENED } from '@vegaprotocol/crypto'
const wallet = await VegaWallet.fromMnemonic('...')
const keys = await wallet.keyPair(HARDENED + 0)
const msg = Buffer.from('Hello world!')
const signature = await keys.sign(msg)
Note: All APIs are async. In some cases they will run sync, eg in Node.js where loading WASM is sync, or where crypto routines are sync, but everything is kept async as a lowest common denominator between browser APIs and future hardware wallet support.
Derive a new SLIP-10 VegaWallet
from a BIP-0039 mnemonic. Note that the
mnemonic is not validated before key derivation.
Derive a seed
from a BIP-0039 mnemonic. In combination with
VegaWallet.fromSeed
this is equivalent to VegaWallet.fromMnemonic
.
Note that the mnemonic is not validated before key derivation.
Derive a new SLIP-10 VegaWallet
from a seed
.
Generate a new key pair at index
, under the Vega specific subtree.
This contains name
and version
detailing the version used by the
instantiated keyPair. Note if this changes in the future other "builder"
methods will be exposed to derive newer versions.
Sign msg
with key pair kp
for optional chainId
.
Verify sig
is valid for msg
under key pair kp
for optional chainId
.
See algorithm.md and test-vectors.