From 997aa7e72adec8ff4d83010c4089f2c733e01363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20Bardaj=C3=AD=20Puig?= Date: Thu, 11 Jul 2024 20:06:39 +0100 Subject: [PATCH] Add optional broadcast param --- package-lock.json | 4 ++-- package.json | 2 +- src/request/types/stxMethods.ts | 42 +++++++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 28f979c..9823dc8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@sats-connect/core", - "version": "0.0.15", + "version": "0.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@sats-connect/core", - "version": "0.0.15", + "version": "0.1.0", "license": "ISC", "dependencies": { "axios": "1.6.8", diff --git a/package.json b/package.json index 11bc44c..9a22fbb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sats-connect/core", - "version": "0.0.15", + "version": "0.1.0", "main": "dist/index.mjs", "module": "dist/index.mjs", "types": "dist/index.d.mts", diff --git a/src/request/types/stxMethods.ts b/src/request/types/stxMethods.ts index 2309d99..3a88dc6 100644 --- a/src/request/types/stxMethods.ts +++ b/src/request/types/stxMethods.ts @@ -287,10 +287,42 @@ export type StxGetAddresses = MethodParamsAndResult< v.InferOutput >; -// Types for `stx_signTransaction` request -export type SignTransactionParams = Transaction & Partial; -export type SignTransactionResult = Transaction; +export const stxSignTransactionMethodName = 'stx_signTransaction'; +export const stxSignTransactionParamsSchema = v.object({ + /** + * The transaction to sign as a hex-encoded string. + */ + transaction: v.string(), + /** + * The public key to sign the transaction with. The wallet may use any key + * when not provided. + */ + pubkey: v.optional(v.string()), + /** + * Whether to broadcast the transaction after signing. Defaults to `true`. + */ + broadcast: v.optional(v.boolean()), +}); +export type StxSignTransactionParams = v.InferOutput; +export const stxSignTransactionResultSchema = v.object({ + /** + * The signed transaction as a hex-encoded string. + */ + transaction: v.string(), +}); +export type StxSignTransactionResult = v.InferOutput; +export const stxSignTransactionRequestMessageSchema = v.object({ + ...rpcRequestMessageSchema.entries, + ...v.object({ + method: v.literal(stxSignTransactionMethodName), + params: stxSignTransactionParamsSchema, + id: v.string(), + }).entries, +}); +export type StxSignTransactionRequestMessage = v.InferOutput< + typeof stxSignTransactionRequestMessageSchema +>; export type StxSignTransaction = MethodParamsAndResult< - SignTransactionParams, - SignTransactionResult + StxSignTransactionParams, + StxSignTransactionResult >;