Skip to content

Methods

Wouter den Bakker edited this page Nov 28, 2019 · 2 revisions

Methods/variables of PublicKey:

  • static isValidPublic(buffer): boolean
  • static isValidAddress(string | buffer): boolean
  • static addressAsBuffer(string): buffer
  • static addressAsString(buffer): string
  • static constructor(buffer)
  • publicKey: buffer: The public key in buffer format.
  • getAddress(): string: Get a human usable address belonging to this public/private key.
  • getAddressAsBuffer(): buffer
  • verify(data: buffer, signature: buffer): Verify if a message was signed with this public key.

Methods of PrivateKey:

  • All methods of public key.
  • static generate(): PrivateKey: Generate a new random private key.
  • static generateNonRandom(data: Buffer, salt: Buffer): PrivateKey
  • static fromWIF(string): PrivateKey: Reconstruct a private key from a human usable format.
  • static isValidWIF(): boolean
  • toWIF(): string: Get a human usable formatted private key.
  • sign(buffer): buffer: Sign a piece of data, returning the signature.

Methods of Crypto (all are static).

  • sha1(buffer | string): buffer
  • sha256(buffer | string): buffer
  • sha512(buffer | string): buffer
  • ripemd160(buffer | string): buffer
  • md5(buffer | string): buffer
  • hash256(buffer | string): buffer: shortcut for sha256(sha256())
  • hash160(buffer | string): buffer: shortcut for ripemd160(sha256())
  • is{Hex,Base58,Base64,Base64Url}(string): boolean;
  • {utf8,hex,base58,base64,base64Url}ToBinary(string): buffer
  • binaryTo{Utf8,Hex,Base58,Base64,Base64Url}(buffer): string
  • {uInt8,uInt16,uInt32,uLong}ToBinary(number): buffer
  • binaryTo{UInt8,UInt16,UInt32,ULong}(buffer): number
  • id(): buffer: 16 bytes of random data

Methods of Log (all are static):

  • Level: defaults to Log.Warning: Do not log messages below said level.
  • options.tags: If logging to Sentry set extra tags by adding them to this object.
  • setReportErrors(dns, ignoreLocalHost): If using Sentry call this with the sentry dns to log errors to Sentry.
  • setUser(string): If using Sentry set the user that is currently using your application.
  • setRelease(string): If using Sentry use this to set the release of your application.
  • debug(string, Error?): void
  • info(string, Error?): void
  • warn(string, Error?): void
  • error(string, Error?): void
  • fatal(string, Error?): void

Methods of Block:

  • constructor(buffer | databaseRow): Create a new block from binary data or from a database row. Throws if the block could not be constructed, but does not verify its transactions, signature of hash referring to the previous block.
  • static merge(Block[]): buffer: Turn a list of blocks into binary data.
  • static unmerge(buffer): Block[]: Turn binary data into a list of blocks.
  • static sign(block, prefix, privateKey): Block: Create a block by signing an unsigned block with provided prefix and private key.
  • verifySignature(prefix, publickey): boolean: Verifies if the signature of this block is correct.
  • verifyWithPreviousBlock(prefix, previousBlock: Block): boolean: Check if the hash indeed refers to the previous block.
  • getPreviousBlockHash(): buffer
  • getTransactions(): buffer: Can be turned into a list of transactions with Transaction.unmerge()
  • getSignature(): buffer
  • getHash(prefix): buffer
  • version: number
  • id: number
  • processedTs: number
  • transactionsAmount: number

Methods of Transaction:

  • constructor(buffer | databaseRow): Create a transaction from binary data or from a row from the database. Will throw if the transaction could not be constructed, but does not verify the payload or the signature.
  • static merge(Transaction[]): buffer: Turn a list of transactions into binary data.
  • static unmerge(buffer): Transaction[]: Turn binary data into a list of transactions.
  • static sign(transaction, prefix, privateKey): Transaction: Create a transaction by signing an unsigned transactions with provided prefix and private key.
  • static generateId(): Generate a random transaction id.
  • verifySignature(prefix): boolean: Verifies if the signature of this transaction is correct.
  • verifyTemplate(template, contractVersion): string | undefined: Verifies if the payload of this transactions matches a certain template (for the given contract version). Returns a string with a description of what is wrong or undefined if everything is correct.
  • getId(): buffer
  • getContractHash(): buffer
  • getPayloadBinary(): buffer
  • getSignature(): buffer
  • getPublicKeyBuffer(): buffer
  • getAddress(): string: The address belonging to the public key of this transaction.
  • getPayloadJson(): object | undefined: Returns the payload of this transaction. If the payload is not a valid json object undefined will be returned instead.
  • version: number
  • validTill: number

Methods of Sandbox: The sandbox object is meant to enforce determinism and provide some security against mistakes, but is not meant to provide security against a malicious party. Methods such as Date.now(), Math.random() and Number.toLocaleString() are unavailable. Functions used in smart contracts are made globally available, after which the global object is frozen to avoid further changes.

  • static sandbox(): Enter the sandbox.
  • static unSandbox(): Leave the sandbox.
  • static isSandboxed(): If the application is currently sandboxed.

Clone this wiki locally