From b253d37e7ed4266af17d3cf3815963cf30ab4901 Mon Sep 17 00:00:00 2001 From: Umair Sarfraz Date: Fri, 18 Feb 2022 12:03:15 +0100 Subject: [PATCH] feat: update nodejs bindings (#872) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: update nodejs bindings - Change address outputs from an array to a list (object); - Add “id” to Message interface; - Make “confirmed” property in Message interface non-optional; - Add “reattachmentMessageId” to Message interface; - Add “type: ‘Transaction’” to Transaction interface; - Nest “Transaction.essense” into “Transaction.data”; - Make “metadata” in UTXOInput interface non-optional; - Change “is_spent” in UTXOInput interface to “isSpent”; - Add “Indexation” payload to RegularEssence interface; - Add unlock_blocks to Message interface — (TODO) Should be camelCase including public_key prop; - Add Milestone payload interface * feat: make unlock_blocks camelCase * fix (nodejs): address comments - make metadata in UtxoInput interface optional; - make payload in RegularEssence interface optional * chore: add to .changes/ for next release --- .changes/type-definitions.md | 5 ++ bindings/nodejs/lib/index.d.ts | 106 ++++++++++++++++++++++++++++----- src/message.rs | 1 + 3 files changed, 96 insertions(+), 16 deletions(-) create mode 100644 .changes/type-definitions.md diff --git a/.changes/type-definitions.md b/.changes/type-definitions.md new file mode 100644 index 000000000..7e957ff2b --- /dev/null +++ b/.changes/type-definitions.md @@ -0,0 +1,5 @@ +--- +"nodejs-binding": patch +--- + +Update nodejs type definitions diff --git a/bindings/nodejs/lib/index.d.ts b/bindings/nodejs/lib/index.d.ts index 01aedb14e..f40dae1fc 100644 --- a/bindings/nodejs/lib/index.d.ts +++ b/bindings/nodejs/lib/index.d.ts @@ -16,7 +16,13 @@ export declare enum MessageType { export declare interface RegularEssence { inputs: Input[]; outputs: Output[]; - payload?: Payload[]; + payload?: { + type: 'Indexation' + data: { + data: number[] + index: number[] + } + }; incoming: boolean; internal: boolean; value: number; @@ -35,7 +41,7 @@ export declare interface UtxoInput { messageId: string; index: number; amount: number; - is_spent: boolean; + isSpent: boolean; address: string; }; } @@ -54,31 +60,96 @@ export declare interface SignatureLockedDustAllowance { remainder: boolean; } -export declare type Output = - | { - type: 'SignatureLockedSingleOutput'; - data: SignatureLockedSingleOutput; - } - | { - type: 'SignatureLockedDustAllowance'; - data: SignatureLockedDustAllowance; - }; +export declare type Output = { + type: 'SignatureLockedSingleOutput'; + data: SignatureLockedSingleOutput; +} | { + type: 'SignatureLockedDustAllowance'; + data: SignatureLockedDustAllowance; +}; export declare interface Transaction { - essence: Essence; + type: 'Transaction'; + data: { + essence: Essence; + unlockBlocks: { + type: 'Signature' + data: { + type: 'Ed25519' + data: { + public_key: number[] + signature: number[] + } + } + }[] + } +} + +interface ReceiptFunds { + output: { + address: string + amount: number + remainder: boolean + } + tailTransactionHash: string +} + +interface Receipt { + type: 'Receipt' + data: { + last: boolean + migratedAt: number + funds: ReceiptFunds[] + transaction: { + data: { + input: { + data: string + type: 'Treasury' + } + output: { + data: { + amount: number + } + } + } + type: 'TreasuryTransaction' + } + } +} + +interface MilestoneEssence { + index: number + merkleProof: number[] + nextPowScore: number + nextPowScoreMilestoneIndex: number + parents: string[] + publicKeys: number[] + receipt: Receipt + timestamp: number + value: number +} + +export interface Milestone { + type: 'Milestone' + data: { + essence: MilestoneEssence + signatures: number[] + } } -export declare type Payload = Transaction; +export declare type Payload = Transaction | Milestone; export declare interface Message { + id: string; version: number; parents: string[]; payloadLength: number; payload: Payload; timestamp: string; nonce: number; - confirmed?: boolean; + confirmed: boolean; broadcasted: boolean; + reattachmentMessageId?: string | null; } export declare interface AddressOutput { @@ -95,7 +166,9 @@ export declare interface Address { balance: number; keyIndex: number; internal: boolean; - outputs: AddressOutput[]; + outputs: { + [outputId: string]: AddressOutput + }; } export declare interface SyncOptions { @@ -203,7 +276,7 @@ export declare class OutputKind { static signatureLockedDustAllowance(): OutputKind; } -export declare class SyncedAccount {} +export declare class SyncedAccount { } export declare type NodeUrl = string; @@ -279,6 +352,7 @@ export declare interface TransactionEvent { accountId: string; message: Message; } + export declare class AccountManager { constructor(options: ManagerOptions); startBackgroundSync( diff --git a/src/message.rs b/src/message.rs index f9d99c738..dfc1bc110 100644 --- a/src/message.rs +++ b/src/message.rs @@ -748,6 +748,7 @@ impl TransactionEssence { #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] pub struct MessageTransactionPayload { essence: TransactionEssence, + #[serde(rename = "unlockBlocks")] unlock_blocks: Box<[UnlockBlock]>, }