diff --git a/CHANGELOG.md b/CHANGELOG.md index e560229d..ed58a30f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- API breaking: `secretjs.tx.signTx()` now returns `txBytes` as a `Uint8Array` instead of a base64 `string`. +- API breaking: `secretjs.tx.broadcastSignedTx()` now receives `txBytes` as a `Uint8Array` instead of a base64 `string`. + ## 1.9.3 Fix a bug where error messages would sometimes not decrypt on highly nested contract calls. diff --git a/src/secret_network_client.ts b/src/secret_network_client.ts index f4e8de06..937fe5d1 100644 --- a/src/secret_network_client.ts +++ b/src/secret_network_client.ts @@ -601,9 +601,24 @@ export type TxSender = { */ broadcast: (messages: Msg[], txOptions?: TxOptions) => Promise; - signTx: (messages: Msg[], txOptions?: TxOptions) => Promise; + /** + * Prepare and sign an array of messages as a transaction + * @async + * @param {Msg[]} messages - Array of messages to prepare and sign + * @param {TxOptions} [txOptions] - An optional object of transaction options + * @returns {Promise} Returns a Promise that resolves txBytes, which can be passed into broadcastSignedTx(). + */ + signTx: (messages: Msg[], txOptions?: TxOptions) => Promise; + + /** + * Broadcast a signed transactions + * @async + * @param {Uint8Array} txBytes - Signed transaction bytes, can be the output of signTx() + * @param {TxOptions} [txOptions] - An optional object of transaction options + * @returns {Promise} + */ broadcastSignedTx: ( - signedMessage: string, + txBytes: Uint8Array, txOptions?: TxOptions, ) => Promise; @@ -1595,20 +1610,33 @@ export class SecretNetworkClient { } } + /** + * Prepare and sign an array of messages as a transaction + * @async + * @private + * @param {Msg[]} messages - Array of messages to prepare and sign + * @param {TxOptions} [txOptions] - An optional object of transaction options + * @returns {Promise} Returns a Promise that resolves txBytes, which can be passed into broadcastSignedTx(). + */ private async signTx( messages: Msg[], txOptions?: TxOptions, - ): Promise { - let signed = await this.prepareAndSign(messages, txOptions); - - return toBase64(signed); + ): Promise { + return this.prepareAndSign(messages, txOptions); } + /** + * Broadcast a signed transactions + * @async + * @private + * @param {Uint8Array} txBytes - Signed transaction bytes, can be the output of signTx() + * @param {TxOptions} [txOptions] - An optional object of transaction options + * @returns {Promise} + */ private async broadcastSignedTx( - messages: string, + txBytes: Uint8Array, txOptions?: TxOptions, ): Promise { - let txBytes = fromBase64(messages); return this.broadcastTx( txBytes, txOptions?.broadcastTimeoutMs ?? 60_000,