From 2d3e90808cd0e9bc539a6d3d7c9067b5c41d242c Mon Sep 17 00:00:00 2001 From: Damian Orzepowski Date: Fri, 16 Aug 2024 11:55:03 +0200 Subject: [PATCH] fix(SPV-999): SharedConfig type is not representing server response correctly. (#1069) --- examples/get-handled-paymail-domains.ts | 19 +++++++++++++++++++ examples/package.json | 5 +++-- package.json | 2 +- src/types.ts | 4 ++-- 4 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 examples/get-handled-paymail-domains.ts diff --git a/examples/get-handled-paymail-domains.ts b/examples/get-handled-paymail-domains.ts new file mode 100644 index 00000000..0a219e04 --- /dev/null +++ b/examples/get-handled-paymail-domains.ts @@ -0,0 +1,19 @@ +import { SpvWalletClient } from '../dist/typescript-npm-package.cjs.js'; +import { exampleAdminKey, exampleXPriv } from './example-keys.js'; +import { errMessage } from './utils.js'; + +const server = 'http://localhost:3003/v1'; + +// It is possible to get paymail domains either as an admin or as a user. +if (!exampleAdminKey && !exampleXPriv) { + console.log(errMessage('adminKey'), 'or', errMessage('xPriv')); + process.exit(1); +} + +const client = exampleXPriv + ? new SpvWalletClient(server, { xPriv: exampleXPriv }) + : new SpvWalletClient(server, { adminKey: exampleAdminKey }); + +const sharedConfig = await client.GetSharedConfig(); + +console.log(sharedConfig.paymail_domains[0]); diff --git a/examples/package.json b/examples/package.json index 040c67c7..bdbb22d2 100644 --- a/examples/package.json +++ b/examples/package.json @@ -5,7 +5,7 @@ "preinstall": "cd ../ && yarn install && yarn build", "build": "tsc", "build:client": "cd .. && yarn build", - "run:example": "yarn build:client && node --loader ts-node/esm", + "run:example": "yarn build:client && echo '==== Starting ====\n' && node --loader ts-node/esm", "admin-add-user": "yarn run:example admin-add-user.ts", "admin-remove-user": "yarn run:example admin-remove-user.ts", "create-transaction": "yarn run:example create-transaction.ts", @@ -17,7 +17,8 @@ "send-op-return": "yarn run:example send-op-return.ts", "xpriv-from-mnemonic": "yarn run:example xpriv-from-mnemonic.ts", "xpub-from-xpriv": "yarn run:example xpub-from-xpriv.ts", - "generate-totp": "yarn run:example generate-totp.ts" + "generate-totp": "yarn run:example generate-totp.ts", + "get-handled-paymail-domains": "yarn run:example get-handled-paymail-domains.ts" }, "version": "0.0.0", "devDependencies": { diff --git a/package.json b/package.json index 8bd21609..ce8f6b38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bsv/spv-wallet-js-client", - "version": "1.0.0-beta.19", + "version": "1.0.0-beta.20", "description": "TypeScript library for connecting to a SPV Wallet server", "repository": { "type": "git", diff --git a/src/types.ts b/src/types.ts index 1ebbaa40..57f9b9eb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -678,13 +678,13 @@ export interface SharedConfig { /** * PaymailDomains is an array of strings representing the allowed Paymail domains. */ - PaymailDomains: string[]; + paymail_domains: string[]; /** * ExperimentalFeatures is a map of experimental features handled by spv-wallet. * The keys are strings representing the feature names, and the values are booleans representing whether the feature is enabled or not. */ - ExperimentalFeatures: { [key: string]: boolean }; + experimental_features: { [key: string]: boolean }; } export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';