Crypto
@aeternity/aepp-sdk/es/utils/crypto
Crypto module
Example
import * as Crypto from '@aeternity/aepp-sdk/es/utils/crypto'
- @aeternity/aepp-sdk/es/utils/crypto
- static
- .decode ⇒
Array
- .formatAddress(format, address) ⇒
String
- .isAddressValid(address, prefix) ⇒
Boolean
- .addressToHex(base58CheckAddress) ⇒
String
- .addressFromDecimal(decimalAddress) ⇒
String
- .hash(input) ⇒
Buffer
- .sha256hash(input) ⇒
String
- .salt() ⇒
Number
- .encodeBase64Check(input) ⇒
Buffer
- .decodeBase64Check(str) ⇒
Buffer
- .encodeBase58Check(input) ⇒
String
- .decodeBase58Check(str) ⇒
Buffer
- .hexStringToByte(str) ⇒
Uint8Array
- .encodeUnsigned(value) ⇒
Buffer
- .encodeContractAddress(owner, nonce) ⇒
String
- .generateKeyPairFromSecret(secret) ⇒
Object
- .generateKeyPair(raw) ⇒
Object
- .encryptPublicKey(password, binaryKey) ⇒
Uint8Array
- .encryptPrivateKey(password, binaryKey) ⇒
Uint8Array
- .encryptKey(password, binaryData) ⇒
Uint8Array
- .decryptKey(password, encrypted) ⇒
Buffer
- .sign(data, privateKey) ⇒
Buffer
- .verify(str, signature, publicKey) ⇒
Boolean
- .prepareTx(signature, data) ⇒
Transaction
- .aeEncodeKey(binaryKey) ⇒
String
- .generateSaveWallet(password) ⇒
Object
- .decryptPrivateKey(password) ⇒
Buffer
- .decryptPubKey(password) ⇒
Buffer
- .assertedType(data, type, forceError) ⇒
String
|Boolean
- .decodeTx(txHash) ⇒
Buffer
- .encodeTx(txData) ⇒
String
- .isValidKeypair(privateKey, publicKey) ⇒
Boolean
- .envKeypair(env, [force]) ⇒
Object
- .encryptData(msg, publicKey) ⇒
Object
- .decryptData(secretKey, encryptedData) ⇒
Buffer
|null
- .decode ⇒
- inner
- ~Transaction :
Array
- ~Transaction :
- static
@aeternity/aepp-sdk/es/utils/crypto.decode ⇒ Array
RLP decode
Kind: static constant of @aeternity/aepp-sdk/es/utils/crypto
Returns: Array
- Array of Buffers containing the original message
rtype: (data: Any) => Buffer[]
Param | Type | Description |
---|---|---|
data | Buffer | String | Integer | Array |
Data to decode |
@aeternity/aepp-sdk/es/utils/crypto.formatAddress(format, address) ⇒ String
Format account address
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: String
- Formatted address
rtype: (format: String, address: String) => tx: Promise[String]
Param | Type | Description |
---|---|---|
format | String |
Format type |
address | String |
Base58check account address |
@aeternity/aepp-sdk/es/utils/crypto.isAddressValid(address, prefix) ⇒ Boolean
Check if address is valid
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Boolean
- valid
rtype: (input: String) => valid: Boolean
Param | Type | Description |
---|---|---|
address | String |
Address |
prefix | String |
Transaction prefix. Default: 'ak' |
@aeternity/aepp-sdk/es/utils/crypto.addressToHex(base58CheckAddress) ⇒ String
Convert base58Check address to hex string
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: String
- Hex string
rtype: (base58CheckAddress: String) => hexAddress: String
Param | Type | Description |
---|---|---|
base58CheckAddress | String |
Address |
@aeternity/aepp-sdk/es/utils/crypto.addressFromDecimal(decimalAddress) ⇒ String
Parse decimal address and return base58Check encoded address with prefix 'ak'
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: String
- address
rtype: (input: String) => address: String
Param | Type | Description |
---|---|---|
decimalAddress | String |
Address |
@aeternity/aepp-sdk/es/utils/crypto.hash(input) ⇒ Buffer
Calculate 256bits Blake2b hash of input
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Buffer
- Hash
rtype: (input: String) => hash: String
Param | Type | Description |
---|---|---|
input | String | Buffer |
Data to hash |
@aeternity/aepp-sdk/es/utils/crypto.sha256hash(input) ⇒ String
Calculate SHA256 hash of input
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: String
- Hash
rtype: (input: String) => hash: String
Param | Type | Description |
---|---|---|
input | String |
Data to hash |
@aeternity/aepp-sdk/es/utils/crypto.salt() ⇒ Number
Generate a random salt (positive integer)
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Number
- random salt
rtype: () => salt: Number
@aeternity/aepp-sdk/es/utils/crypto.encodeBase64Check(input) ⇒ Buffer
Base64check encode given input
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Buffer
- Base64check encoded data
rtype: (input: String|buffer) => Buffer
Param | Type | Description |
---|---|---|
input | String |
Data to encode |
@aeternity/aepp-sdk/es/utils/crypto.decodeBase64Check(str) ⇒ Buffer
Base64check decode given str
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Buffer
- Base64check decoded data
rtype: (str: String) => Buffer
Param | Type | Description |
---|---|---|
str | String |
Data to decode |
@aeternity/aepp-sdk/es/utils/crypto.encodeBase58Check(input) ⇒ String
Base58 encode given input
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: String
- Base58 encoded data
rtype: (input: String) => String
Param | Type | Description |
---|---|---|
input | String | Buffer |
Data to encode |
@aeternity/aepp-sdk/es/utils/crypto.decodeBase58Check(str) ⇒ Buffer
Base58 decode given str
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Buffer
- Base58 decoded data
rtype: (str: String) => Buffer
Param | Type | Description |
---|---|---|
str | String |
Data to decode |
@aeternity/aepp-sdk/es/utils/crypto.hexStringToByte(str) ⇒ Uint8Array
Conver hex string to Uint8Array
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Uint8Array
- - converted data
rtype: (str: String) => Uint8Array
Param | Type | Description |
---|---|---|
str | String |
Data to conver |
@aeternity/aepp-sdk/es/utils/crypto.encodeUnsigned(value) ⇒ Buffer
Converts a positive integer to the smallest possible representation in a binary digit representation
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Buffer
- - Encoded data
rtype: (value: Number) => Buffer
Param | Type | Description |
---|---|---|
value | Number |
Value to encode |
@aeternity/aepp-sdk/es/utils/crypto.encodeContractAddress(owner, nonce) ⇒ String
Compute contract address
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: String
- - Contract address
rtype: (owner: String, nonce: Number) => String
Param | Type | Description |
---|---|---|
owner | String |
Address of contract owner |
nonce | Number |
Round when contract was created |
@aeternity/aepp-sdk/es/utils/crypto.generateKeyPairFromSecret(secret) ⇒ Object
Generate keyPair from secret key
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Object
- - Object with Private(privateKey) and Public(publicKey) keys
rtype: (secret: Uint8Array) => KeyPair
Param | Type | Description |
---|---|---|
secret | Uint8Array |
secret key |
@aeternity/aepp-sdk/es/utils/crypto.generateKeyPair(raw) ⇒ Object
Generate a random ED25519 keypair
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Object
- Key pair
rtype: (raw: Boolean) => {publicKey: String, secretKey: String} | {publicKey: Buffer, secretKey: Buffer}
Param | Type | Description |
---|---|---|
raw | Boolean |
Whether to return raw (binary) keys |
@aeternity/aepp-sdk/es/utils/crypto.encryptPublicKey(password, binaryKey) ⇒ Uint8Array
Encrypt given public key using password
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Uint8Array
- Encrypted key
rtype: (password: String, binaryKey: Buffer) => Uint8Array
Param | Type | Description |
---|---|---|
password | String |
Password to encrypt with |
binaryKey | Buffer |
Key to encrypt |
@aeternity/aepp-sdk/es/utils/crypto.encryptPrivateKey(password, binaryKey) ⇒ Uint8Array
Encrypt given private key using password
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Uint8Array
- Encrypted key
rtype: (password: String, binaryKey: Buffer) => Uint8Array
Param | Type | Description |
---|---|---|
password | String |
Password to encrypt with |
binaryKey | Buffer |
Key to encrypt |
@aeternity/aepp-sdk/es/utils/crypto.encryptKey(password, binaryData) ⇒ Uint8Array
Encrypt given data using password
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Uint8Array
- Encrypted data
rtype: (password: String, binaryData: Buffer) => Uint8Array
Param | Type | Description |
---|---|---|
password | String |
Password to encrypt with |
binaryData | Buffer |
Data to encrypt |
@aeternity/aepp-sdk/es/utils/crypto.decryptKey(password, encrypted) ⇒ Buffer
Decrypt given data using password
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Buffer
- Decrypted data
rtype: (password: String, encrypted: String) => Uint8Array
Param | Type | Description |
---|---|---|
password | String |
Password to decrypt with |
encrypted | String |
Data to decrypt |
@aeternity/aepp-sdk/es/utils/crypto.sign(data, privateKey) ⇒ Buffer
Generate signature
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Buffer
- Signature
rtype: (data: String|Buffer, privateKey: Buffer) => Buffer
Param | Type | Description |
---|---|---|
data | String | Buffer |
Data to sign |
privateKey | String | Buffer |
Key to sign with |
@aeternity/aepp-sdk/es/utils/crypto.verify(str, signature, publicKey) ⇒ Boolean
Verify that signature was signed by public key
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Boolean
- Valid?
rtype: (str: String, signature: Buffer, publicKey: Buffer) => Boolean
Param | Type | Description |
---|---|---|
str | String | Buffer |
Data to verify |
signature | Buffer |
Signature to verify |
publicKey | Buffer |
Key to verify against |
@aeternity/aepp-sdk/es/utils/crypto.prepareTx(signature, data) ⇒ Transaction
Prepare a transaction for posting to the blockchain
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Transaction
- Transaction
rtype: (signature: Buffer | String, data: Buffer) => Transaction
Param | Type | Description |
---|---|---|
signature | Buffer |
Signature of data |
data | Buffer |
Transaction data |
@aeternity/aepp-sdk/es/utils/crypto.aeEncodeKey(binaryKey) ⇒ String
æternity readable public keys are the base58-encoded public key, prepended with 'ak_'
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: String
- Encoded key
rtype: (binaryKey: Buffer) => String
Param | Type | Description |
---|---|---|
binaryKey | Buffer |
Key to encode |
@aeternity/aepp-sdk/es/utils/crypto.generateSaveWallet(password) ⇒ Object
Generate a new key pair using generateKeyPair and encrypt it using password
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Object
- Encrypted key pair
rtype: (password: String) => {publicKey: Uint8Array, secretKey: Uint8Array}
Param | Type | Description |
---|---|---|
password | String |
Password to encrypt with |
@aeternity/aepp-sdk/es/utils/crypto.decryptPrivateKey(password) ⇒ Buffer
Decrypt an encrypted private key
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Buffer
- Decrypted key
rtype: (password: String, encrypted: Buffer) => Buffer
Param | Type | Description |
---|---|---|
password | String |
Password to decrypt with |
@aeternity/aepp-sdk/es/utils/crypto.decryptPubKey(password) ⇒ Buffer
Decrypt an encrypted public key
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Buffer
- Decrypted key
rtype: (password: String, encrypted: Buffer) => Buffer
Param | Type | Description |
---|---|---|
password | String |
Password to decrypt with |
@aeternity/aepp-sdk/es/utils/crypto.assertedType(data, type, forceError) ⇒ String
| Boolean
Assert base58 encoded type and return its payload
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: String
| Boolean
- Payload
rtype: (data: String, type: String) => String, throws: Error
Param | Type | Description |
---|---|---|
data | String |
ae data |
type | String |
Prefix |
forceError |
@aeternity/aepp-sdk/es/utils/crypto.decodeTx(txHash) ⇒ Buffer
Decode a transaction
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Buffer
- Decoded transaction
rtype: (txHash: String) => Buffer
Param | Type | Description |
---|---|---|
txHash | String |
Transaction hash |
@aeternity/aepp-sdk/es/utils/crypto.encodeTx(txData) ⇒ String
Encode a transaction
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: String
- Encoded transaction
rtype: (txData: Transaction) => String
Param | Type | Description |
---|---|---|
txData | Transaction |
Transaction to encode |
@aeternity/aepp-sdk/es/utils/crypto.isValidKeypair(privateKey, publicKey) ⇒ Boolean
Check key pair for validity
Sign a message, and then verifying that signature
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Boolean
- Valid?
rtype: (privateKey: Buffer, publicKey: Buffer) => Boolean
Param | Type | Description |
---|---|---|
privateKey | Buffer |
Private key to verify |
publicKey | Buffer |
Public key to verify |
@aeternity/aepp-sdk/es/utils/crypto.envKeypair(env, [force]) ⇒ Object
Obtain key pair from env
Designed to be used with env
from nodejs. Assumes enviroment variables
WALLET_PRIV
and WALLET_PUB
.
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
Returns: Object
- Key pair
rtype: (env: Object) => {publicKey: String, secretKey: String}, throws: Error
Param | Type | Default | Description |
---|---|---|---|
env | Object |
Environment | |
[force] | Boolean |
false |
Force throwing error |
@aeternity/aepp-sdk/es/utils/crypto.encryptData(msg, publicKey) ⇒ Object
This function encrypts a message using base58check encoded and 'ak' prefixed publicKey such that only the corresponding secretKey will be able to decrypt
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
rtype: (msg: String, publicKey: String) => Object
Param | Type | Description |
---|---|---|
msg | Buffer |
Data to encode |
publicKey | String |
Public key |
@aeternity/aepp-sdk/es/utils/crypto.decryptData(secretKey, encryptedData) ⇒ Buffer
| null
This function decrypt a message using secret key
Kind: static method of @aeternity/aepp-sdk/es/utils/crypto
rtype: (secretKey: String, encryptedData: Object) => Buffer|null
Param | Type | Description |
---|---|---|
secretKey | String |
Secret key |
encryptedData | Object |
Encrypted data |
@aeternity/aepp-sdk/es/utils/crypto~Transaction : Array
Kind: inner typedef of @aeternity/aepp-sdk/es/utils/crypto
rtype: Transaction: [tag: Buffer, version: Buffer, [signature: Buffer], data: Buffer]