* Signs a block using the private key of the account. The signature is
* appended to the signature field of the block before being returned.
*
- * @param {(ChangeBlock|ReceiveBlock|SendBlock)} block - The block data to be hashed and signed
+ * @param {(Block)} block - The block data to be hashed and signed
* @param {Key} password - Required to decrypt the private key for signing
* @returns {Promise<string>} Hexadecimal-formatted 64-byte signature
*/
- sign (block: ChangeBlock | ReceiveBlock | SendBlock, password: Key): Promise<string>
+ sign (block: Block, password: Key): Promise<string>
/**
* Validates a Nano address with 'nano' and 'xrb' prefixes
* Derived from https://github.com/alecrios/nano-address-validator
}
/**
-* Represents a block as defined by the Nano cryptocurrency protocol. The Block
-* class is abstract and cannot be directly instantiated. Every block must be one
-* of three derived classes: SendBlock, ReceiveBlock, ChangeBlock.
+* Represents a block as defined by the Nano cryptocurrency protocol.
*/
-declare abstract class Block {
+export declare class Block {
+ #private
+ subtype?: 'send' | 'receive' | 'change'
account: Account
- type: 'state'
- abstract subtype: 'send' | 'receive' | 'change'
- abstract previous: string
- abstract representative: Account
- abstract balance: bigint
- abstract link: string
- abstract signature?: string
- abstract work?: string
- constructor (account: Account | string)
+ balance: bigint
+ previous: string
+ representative: Account
+ link?: Uint8Array<ArrayBuffer>
+ signature?: string
+ work?: string
+ constructor (account: string | Account, balance?: bigint | string, previous?: string, representative?: string | Account, signature?: string, work?: string)
/**
* Calculates the block hash using Blake2b.
*
- * @returns {Promise<string>} Block data hashed to a byte array
+ * @returns {Uint8Array<ArrayBuffer>} Block data hashed to a byte array
*/
- get hash (): string
+ get hash (): Uint8Array<ArrayBuffer>
/**
* Converts the block to JSON format as expected by the `process` RPC.
*
[key: string]: string
}
/**
+ * Set the subtype and link to configure this as a change representative block.
+ *
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ change (): Block
+ /**
+ * Set a block hash as the source send of a receive block.
+ *
+ * @param {string} hash - Hash of send block to be received
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ from (hash: string): Block
+ /**
+ * Set a send block as the source of a receive block.
+ *
+ * @param {Block} block - Send block to be received
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ from (block: Block): Block
+ /**
* Calculates proof-of-work using a pool of Web Workers.
*
* A successful response sets the `work` property.
*/
- pow (): Promise<void>
+ pow (): Promise<Block>
/**
* Sends the block to a node for processing on the network.
*
*/
process (rpc: Rpc): Promise<string>
/**
+ * Set the amount of nano that this block will receive from a paired send.
+ *
+ * @param {bigint} amount - Amount that was sent from sender in raw
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ receive (amount: bigint): Block
+ /**
+ * Set the amount of nano that this block will receive from a paired send.
+ *
+ * @param {number} amount - Amount that was sent from sender in nano (10³⁰ raw)
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ receive (amount: number): Block
+ /**
+ * Set the amount of nano that this block will receive from a paired send.
+ *
+ * @param {string} amount - Amount that was sent from sender in raw
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ receive (amount: string): Block
+ /**
+ * Set the amount of nano that this block will send to a recipient account.
+ *
+ * @param {bigint} amount - Amount to send to recipient in raw
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ send (amount: bigint): Block
+ /**
+ * Set the amount of nano that this block will send to a recipient account.
+ *
+ * @param {number} amount - Amount to send to recipient in nano (10³⁰ raw)
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ send (amount: number): Block
+ /**
+ * Set the amount of nano that this block will send to a recipient account.
+ *
+ * @param {string} amount - Amount to send to recipient in raw
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ send (amount: string): Block
+ /**
* Signs the block using a private key. If successful, the result is stored in
* the object's `signature` property.
*
* @param {string} [key] - Hexadecimal-formatted private key to use for signing
*/
- sign (key?: string): Promise<void>
+ sign (key: string): Promise<Block>
+ /**
+ * Signs the block using a Wallet. If successful, the result is stored in
+ * the object's `signature` property. The wallet must be unlocked prior to
+ * signing.
+ *
+ * @param {Wallet} wallet - Wallet to use for signing
+ * @param {number} index - Account in wallet to use for signing
+ */
+ sign (wallet: Wallet, index: number): Promise<Block>
/**
* Signs the block using a Ledger hardware wallet. If that fails, an error is
* thrown with the status code from the device.
* @param {number} index - Account index between 0x0 and 0x7fffffff
* @param {object} [frontier] - JSON of frontier block for offline signing
*/
- sign (index?: number, frontier?: ChangeBlock | ReceiveBlock | SendBlock): Promise<void>
+ sign (index: number, frontier?: Block): Promise<Block>
+ /**
+ * Set the recipient of a send block or the target representative of a change
+ * block.
+ *
+ * @param {string} account - Address or public key of Account to target
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ to (account: string): Block
+ /**
+ * Set the recipient of a send block or the target representative of a change
+ * block.
+ *
+ * @param {Account} account - Account to target
+ * @returns {Block} This block so that additional calls can be chained
+ */
+ to (account: Account): Block
/**
* Verifies the signature of the block. If a key is not provided, the public
* key of the block's account will be used if it exists.
*/
verify (key?: string): Promise<boolean>
}
-/**
-* Represents a block that sends funds from one address to another as defined by
-* the Nano cryptocurrency protocol.
-*/
-export declare class SendBlock extends Block {
- type: 'state'
- subtype: 'send'
- previous: string
- representative: Account
- balance: bigint
- link: string
- signature?: string
- work?: string
- constructor (sender: Account | string, balance: string, recipient: string, amount: string, representative: Account | string, frontier: string, work?: string)
-}
-/**
-* Represents a block that receives funds sent to one address from another as
-* defined by the Nano cryptocurrency protocol.
-*/
-export declare class ReceiveBlock extends Block {
- type: 'state'
- subtype: 'receive'
- previous: string
- representative: Account
- balance: bigint
- link: string
- signature?: string
- work?: string
- constructor (recipient: Account | string, balance: string, origin: string, amount: string, representative: Account | string, frontier?: string, work?: string)
-}
-/**
-* Represents a block that changes the representative account to which the user
-* account delegates their vote weight using the the Open Representative Voting
-* specification as defined by the Nano cryptocurrency protocol.
-*/
-export declare class ChangeBlock extends Block {
- type: 'state'
- subtype: 'change'
- previous: string
- representative: Account
- balance: bigint
- link: string
- signature?: string
- work?: string
- constructor (account: Account | string, balance: string, representative: Account | string, frontier: string, work?: string)
-}
export type Data = boolean | number | number[] | string | string[] | ArrayBuffer | CryptoKey | { [key: string]: Data }
* before being returned. The wallet must be unlocked prior to signing.
*
* @param {number} index - Account to use for signing
- * @param {(ChangeBlock|ReceiveBlock|SendBlock)} block - Block data to be hashed and signed
+ * @param {(Block)} block - Block data to be hashed and signed
* @returns {Promise<string>} Hexadecimal-formatted 64-byte signature
*/
- sign (index: number, block: ChangeBlock | ReceiveBlock | SendBlock): Promise<string>
+ sign (index: number, block: Block): Promise<string>
/**
* Unlocks the wallet using the same password as used prior to lock it.
*
interface LedgerSignResponse extends LedgerResponse {
signature: string | null,
- hash?: string
+ hash?: Uint8Array<ArrayBuffer>
}
/**
* Sign a block with the Ledger device.
*
* @param {number} index - Account number
- * @param {object} block - Block data to sign
+ * @param {Block} block - Block data to sign
* @returns {Promise<string>} Signature
*/
- sign (index: number, block: SendBlock | ReceiveBlock | ChangeBlock, frontier?: SendBlock | ReceiveBlock | ChangeBlock): Promise<string>
+ sign (index: number, block: Block, frontier?: Block): Promise<string>
/**
* Attempts to connect to the Ledger device.
*
* Update cache from raw block data. Suitable for offline use.
*
* @param {number} index - Account number
- * @param {object} block - JSON-formatted block data
+ * @param {Block} block - JSON-formatted block data
*/
- updateCache (index: number, block: ChangeBlock | ReceiveBlock | SendBlock): Promise<LedgerResponse>
+ updateCache (index: number, block: Block): Promise<LedgerResponse>
/**
* Update cache from a block hash by calling out to a node. Suitable for online
* use only.