Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(SPV-905): update endpoint use cases #1020

Merged
merged 60 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0d2b365
feat(SPV-905) update endpoint use cases
yarex-4chain Jul 1, 2024
eca2c31
Merge branch 'main' into feat/SPV-905-update-endpoint-use-cases
wregulski Aug 23, 2024
e8c2373
feat(SPV-905): update js-clients to newly updated endpoints
wregulski Aug 23, 2024
cbe2847
fix(SPV-905): resolve unproper syntax for shared config paymail domains
wregulski Aug 26, 2024
2cce5dd
fix(SPV-905): adjust create-transaction example to new rest api inter…
wregulski Aug 26, 2024
567e79f
feat(SPV-905): update models for camelCase fields + add /api/ prefix …
wregulski Aug 26, 2024
7da752f
feat(SPV-905): update examples to work with new models
wregulski Aug 27, 2024
4424da1
Merge branch 'main' into feat/SPV-905-update-endpoint-use-cases
wregulski Aug 28, 2024
1a5880b
feat(SPV-905): update models definitions
wregulski Aug 28, 2024
ec7192d
fix(SPV-905): get back with routes to previous v1
wregulski Aug 30, 2024
aaa7949
fix(SPV-905): proper camelCase on referenceId fields in record transa…
wregulski Aug 30, 2024
623ff89
Merge branch 'main' into feat/SPV-905-update-endpoint-use-cases
wregulski Sep 23, 2024
2212313
feat(SPV-905): add query builder to a spv-wallet-js-client
wregulski Sep 25, 2024
840f158
fix(SPV-905): proper path to a new transaction search
wregulski Sep 25, 2024
527851b
fix(SPV-905): remove redundant /api sufix in README.md
wregulski Sep 25, 2024
14eb166
fix(SPV-905): adjust test fixtures to a camelCase
wregulski Sep 25, 2024
0b75d16
fix(SPV-905): update xpub name to user
wregulski Sep 25, 2024
fdef5fa
checkpoint
wregulski Sep 27, 2024
fa2c9e0
Merge branch 'main' into feat/SPV-905-update-endpoint-use-cases
wregulski Sep 30, 2024
7ecb0f4
fix(SPV-905): make query builder more flexible
wregulski Sep 30, 2024
50aaa16
feat(SPV-905): apply new way of using buildPath func
wregulski Oct 4, 2024
53d990f
chore(SPV-905): remove json stringify
wregulski Oct 4, 2024
afd621b
Update examples/get-shared-config.ts
wregulski Oct 4, 2024
5328ca8
fix(SPV-905): let httpclient resolve proper sufix on serverURL
wregulski Oct 4, 2024
5c7e115
docs(SPV-905): add info that serverURL api sufix is resolved automati…
wregulski Oct 4, 2024
34540a5
feat(SPV-905): add old/deprecated types to cover admin endpoints alon…
wregulski Oct 4, 2024
0acbd7c
feat(SPV-905): adjust query-builder to use URLSearchParam
wregulski Oct 4, 2024
c3f9618
fix(SPV-905): add missing admin methods
wregulski Oct 4, 2024
6130848
fix(SPV-905): add missing dash in update-user-xpub-metadata filename
wregulski Oct 4, 2024
a85d7d6
fix(SPV-905): remove OldWebhooks interface as there are no snake_case…
wregulski Oct 4, 2024
a1c7b34
fix(SPV-905): remove unnecessary /
wregulski Oct 7, 2024
dc720d4
fix(SPV-905): adjust typos/missing words in client.ts
wregulski Oct 7, 2024
e93ce95
Update src/client.ts
wregulski Oct 8, 2024
a8b194d
Update src/client.ts
wregulski Oct 8, 2024
ac3837a
Update src/client.ts
wregulski Oct 8, 2024
7f749f2
Update src/client.ts
wregulski Oct 8, 2024
f1c8f7e
Update src/client.ts
wregulski Oct 8, 2024
1d762d0
Update src/client.ts
wregulski Oct 8, 2024
dbde1bc
Update src/client.ts
wregulski Oct 8, 2024
c3780ed
fix(SPV-905): remove unnecessary paymailaddress model
wregulski Oct 8, 2024
2d5c33e
Update src/client.ts
wregulski Oct 8, 2024
9fe495c
Update src/client.ts
wregulski Oct 8, 2024
2e30599
Update src/client.ts
wregulski Oct 8, 2024
651e1d7
Update src/client.ts
wregulski Oct 8, 2024
26dc095
Update src/client.ts
wregulski Oct 8, 2024
5f555d0
Update src/client.ts
wregulski Oct 8, 2024
acc2d27
Update src/client.ts
wregulski Oct 8, 2024
0cb622a
Update src/client.ts
wregulski Oct 8, 2024
1075115
Update src/client.ts
wregulski Oct 8, 2024
4aad571
Update src/client.ts
wregulski Oct 8, 2024
ddc83bd
Update src/client.ts
wregulski Oct 8, 2024
ddb21ea
Update src/client.ts
wregulski Oct 8, 2024
3a31f2f
Update src/client.ts
wregulski Oct 8, 2024
8287121
fix(SPV-905): remove misleading comment in AdminGetPaymail endpoint
wregulski Oct 8, 2024
4b2f4e0
tests(SPV-905): partially fix regressions tests; TODO: fix response m…
dzolt-4chain Oct 9, 2024
10b572e
tests(SPV-905): rm clog
dzolt-4chain Oct 9, 2024
fe5ca0f
fix(SPV-905): proper types on get paged objects
wregulski Oct 10, 2024
7428cfe
feat(SPV-905): catch exception in create-tx example if something went…
wregulski Oct 10, 2024
c877da1
test(SPV-905): fix regression tests due to changes in models
dzolt-4chain Oct 10, 2024
6764c19
Merge branch 'main' into feat/SPV-905-update-endpoint-use-cases
wregulski Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The main concept is to create a new instance of the `SpvWalletClient` class and
```typescript
import { SpvWalletClient } from '@bsv/spv-wallet-js-client';

const spvWalletServerUrl = 'http://localhost:3003/v1';
const spvWalletServerUrl = 'http://localhost:3003';

// Create a new instance of the SPV Wallet client
const client = new SpvWalletClient(spvWalletServerUrl, {
Expand All @@ -65,8 +65,8 @@ const client = new SpvWalletClient(spvWalletServerUrl, {

// Use the client to interact with the SPV Wallet server
// For example, check the balance
const xpubInfo = await client.GetXPub();
console.log('Current balance:', xpubInfo.current_balance);
const userInfo = await client.GetUser();
console.log('Current balance:', userInfo.currentBalance);
```

> During creation or usage of the client an exception can be thrown - see [handle-exceptions example](./examples/handle-exceptions.ts) how to handle these situations.
Expand All @@ -78,7 +78,7 @@ console.log('Current balance:', xpubInfo.current_balance);

The **first argument** of the `SpvWalletClient` constructor is the URL of the SPV Wallet server.

> Note the `/v1` suffix is required.
> Note the `/api/v1` or /v1 suffix is not required, it will be resolved automatically.

### Keys configuration

Expand Down
26 changes: 26 additions & 0 deletions examples/access-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { SpvWalletClient } from '../dist/typescript-npm-package.cjs.js';
import { exampleXPriv } from './example-keys.js';
import { errMessage } from './utils.js';

const server = 'http://localhost:3003';

if (!exampleXPriv) {
console.log(errMessage('xPriv'));
process.exit(1);
}

const client = new SpvWalletClient(server, {
xPriv: exampleXPriv,
});

const createdAccessKey = await client.CreateAccessKey({ some_metadata: 'example' });
console.log('Created access key ID:', (createdAccessKey.id));
console.log('Metadata:', (createdAccessKey.metadata));
console.log('Created at:', (createdAccessKey.createdAt));

const fetchedAccessKey = await client.GetAccessKeyByID(createdAccessKey.id);
console.log('Fetched access key ID:', (fetchedAccessKey.id));

const revokedAccessKey = await client.RevokeAccessKey(createdAccessKey.id);
console.log('Revoked access key ID:', (revokedAccessKey.id));
console.log('Revoked at:', (revokedAccessKey.revokedAt));
2 changes: 1 addition & 1 deletion examples/admin-add-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SpvWalletClient } from '../dist/typescript-npm-package.cjs.js';
import { exampleAdminKey, exampleXPub, examplePaymail } from './example-keys.js';
import { errMessage } from './utils.js';

const server = 'http://localhost:3003/v1';
const server = 'http://localhost:3003';

if (!exampleAdminKey) {
console.log(errMessage('adminKey'));
Expand Down
2 changes: 1 addition & 1 deletion examples/admin-remove-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SpvWalletClient } from '../dist/typescript-npm-package.cjs.js';
import { exampleAdminKey, examplePaymail } from './example-keys.js';
import { errMessage } from './utils.js';

const server = 'http://localhost:3003/v1';
const server = 'http://localhost:3003';

if (!exampleAdminKey) {
console.log(errMessage('adminKey'));
Expand Down
2 changes: 1 addition & 1 deletion examples/admin-webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SpvWalletClient } from '../dist/typescript-npm-package.cjs.js';
import { exampleAdminKey } from './example-keys.js';
import { errMessage } from './utils.js';

const server = 'http://localhost:3003/v1';
const server = 'http://localhost:3003';

if (!exampleAdminKey) {
console.log(errMessage('adminKey'));
Expand Down
44 changes: 32 additions & 12 deletions examples/create-transaction.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SpvWalletClient } from '../dist/typescript-npm-package.cjs.js';
import { ErrorNoAdminKey, ErrorResponse, SpvWalletClient, SpvWalletError } from '../dist/typescript-npm-package.cjs.js';
import { exampleXPriv } from './example-keys.js';
import { errMessage } from './utils.js';

const server = 'http://localhost:3003/v1';
const server = 'http://localhost:3003';

if (!exampleXPriv) {
console.log(errMessage('xPriv'));
Expand All @@ -13,16 +13,36 @@ const client = new SpvWalletClient(server, {
xPriv: exampleXPriv,
});

const newTransaction = await client.SendToRecipients(
[
try {
const newTransaction = await client.SendToRecipients(
{
to: 'receiver@example.com',
satoshis: 1,
outputs: [
{
to: 'receiver@example.com',
satoshis: 1,
}
]
},
],
{ some_metadata: 'example' },
);
console.log('SendToRecipients response:', newTransaction);
{ some_metadata: 'example' },
);
console.log('SendToRecipients response:', newTransaction);

const tx = await client.GetTransaction(newTransaction.id);
console.log('GetTransaction response:', tx);
const tx = await client.GetTransactionById(newTransaction.id);
console.log('GetTransaction response:', tx);

} catch (e) {
if (e instanceof SpvWalletError) {
// You can check the type of the error and do something specific
if (e instanceof ErrorResponse) {
console.error('Response status:', e.response.status);
console.error('Content:', e.content);
} else if (e instanceof ErrorNoAdminKey) {
console.error('ErrorNoAdminKey', e.message);
} else {
//check all the other error types here: src/errors.ts
console.error('SpvWalletError:', e.message);
}
} else {
console.log('Unknown error:', e);
}
}
2 changes: 1 addition & 1 deletion examples/custom-logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SpvWalletClient, generateKeys } from '../dist/typescript-npm-package.cjs.js';

const server = 'http://localhost:3003/v1';
const server = 'http://localhost:3003';

const newXPub = generateKeys().xPub.toString();

Expand Down
4 changes: 2 additions & 2 deletions examples/generate-totp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SpvWalletClient } from '../dist/typescript-npm-package.cjs.js';

const server = 'http://localhost:3003/v1';
const server = 'http://localhost:3003';

const aliceXPriv =
'xprv9s21ZrQH143K4JFXqGhBzdrthyNFNuHPaMUwvuo8xvpHwWXprNK7T4JPj1w53S1gojQncyj8JhSh8qouYPZpbocsq934cH5G1t1DRBfgbod';
Expand All @@ -19,7 +19,7 @@ const mockBobContact = {
pubKey: bobPKI,

//the rest of the fields won't be used for OTP generation but they still need to be defined
created_at: new Date(),
createdAt: new Date(),
fullName: '',
id: '',
status: '',
Expand Down
6 changes: 3 additions & 3 deletions examples/get-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SpvWalletClient } from '../dist/typescript-npm-package.cjs.js';
import { exampleXPriv } from './example-keys.js';
import { errMessage } from './utils.js';

const server = 'http://localhost:3003/v1';
const server = 'http://localhost:3003';

if (!exampleXPriv) {
console.log(errMessage('xPriv'));
Expand All @@ -13,5 +13,5 @@ const client = new SpvWalletClient(server, {
xPriv: exampleXPriv,
});

const xpubInfo = await client.GetXPub();
console.log('Current balance:', xpubInfo.current_balance);
const userInfo = await client.GetUserInfo();
console.log('Current balance:', userInfo.currentBalance);
4 changes: 2 additions & 2 deletions examples/get-handled-paymail-domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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';
const server = 'http://localhost:3003';

// It is possible to get paymail domains either as an admin or as a user.
if (!exampleAdminKey && !exampleXPriv) {
Expand All @@ -16,4 +16,4 @@ const client = exampleXPriv

const sharedConfig = await client.GetSharedConfig();

console.log(sharedConfig.paymail_domains[0]);
console.log(sharedConfig.paymailDomains[0]);
17 changes: 17 additions & 0 deletions examples/get-shared-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { SpvWalletClient } from '../dist/typescript-npm-package.cjs.js';
import { exampleXPriv } from './example-keys.js';
import { errMessage } from './utils.js';

const server = 'http://localhost:3003';

if (!exampleXPriv) {
console.log(errMessage('xPriv'));
process.exit(1);
}

const client = new SpvWalletClient(server, {
xPriv: exampleXPriv,
});

const sharedConfig = await client.GetSharedConfig();
console.log('Shared config:', sharedConfig);
2 changes: 1 addition & 1 deletion examples/handle-exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ErrorNoAdminKey, ErrorResponse, SpvWalletClient, SpvWalletError } from
import { exampleXPub } from './example-keys.js';
import { errMessage } from './utils.js';

const server = 'http://localhost:3003/v1';
const server = 'http://localhost:3003';

if (!exampleXPub) {
console.log(errMessage('xPub'));
Expand Down
4 changes: 2 additions & 2 deletions examples/list-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SpvWalletClient } from '../dist/typescript-npm-package.cjs.js';
import { exampleXPriv } from './example-keys.js';
import { errMessage } from './utils.js';

const server = 'http://localhost:3003/v1';
const server = 'http://localhost:3003';

if (!exampleXPriv) {
console.log(errMessage('xPriv'));
Expand All @@ -22,7 +22,7 @@ const txsFiltered = await client.GetTransactions(
},
{},
{
page_size: 100,
pageSize: 100,
page: 1,
},
);
Expand Down
9 changes: 6 additions & 3 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
"build:client": "cd .. && yarn build",
"_print_starting_label": "echo '' && echo '========== Starting ==========' && echo ''",
"run:example": "yarn build:client && yarn _print_starting_label && node --loader ts-node/esm",
"access-key": "yarn run:example access-key.ts",
"admin-add-user": "yarn run:example admin-add-user.ts",
"admin-webhooks": "yarn run:example admin-webhooks.ts",
"admin-remove-user": "yarn run:example admin-remove-user.ts",
"create-transaction": "yarn run:example create-transaction.ts",
"custom-logger": "yarn run:example custom-logger.ts",
"generate-totp": "yarn run:example generate-totp.ts",
"generate-keys": "yarn run:example generate-keys.ts",
"get-balance": "yarn run:example get-balance.ts",
"get-handled-paymail-domains": "yarn run:example get-handled-paymail-domains.ts",
"get-shared-config": "yarn run:example get-shared-config.ts",
"handle-exceptions": "yarn run:example handle-exceptions.ts",
"list-transactions": "yarn run:example list-transactions.ts",
"send-op-return": "yarn run:example send-op-return.ts",
"update-user-xpub-metadata": "yarn run:example update-user-xpub-metadata.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",
"get-handled-paymail-domains": "yarn run:example get-handled-paymail-domains.ts"
"xpub-from-xpriv": "yarn run:example xpub-from-xpriv.ts"
},
"version": "0.0.0",
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions examples/send-op-return.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { OpReturn, SpvWalletClient, TransactionConfigInput } from '../dist/typescript-npm-package.cjs.js';
import { DraftTransactionConfig, OpReturn, SpvWalletClient } from '../dist/typescript-npm-package.cjs.js';
import { exampleXPriv } from './example-keys.js';
import { errMessage } from './utils.js';

const server = 'http://localhost:3003/v1';
const server = 'http://localhost:3003';

if (!exampleXPriv) {
console.log(errMessage('xPriv'));
Expand All @@ -14,18 +14,18 @@ const client = new SpvWalletClient(server, {
});

const opReturn: OpReturn = {
string_parts: ['hello', 'world'],
stringParts: ['hello', 'world'],
};

const transactionConfig: TransactionConfigInput = {
const transactionConfig: DraftTransactionConfig = {
outputs: [
{
op_return: opReturn,
opReturn: opReturn,
},
],
};

const draftTransaction = await client.DraftTransaction(transactionConfig, {});
const draftTransaction = await client.NewDraftTransaction(transactionConfig, {});
console.log('DraftTransaction response:', draftTransaction);

const finalized = await client.SignTransaction(draftTransaction);
Expand Down
22 changes: 22 additions & 0 deletions examples/update-user-xpub-metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { SpvWalletClient } from '../dist/typescript-npm-package.cjs.js';
import { exampleXPriv } from './example-keys.js';
import { errMessage } from './utils.js';

const server = 'http://localhost:3003';

if (!exampleXPriv) {
console.log(errMessage('xPriv'));
process.exit(1);
}

const client = new SpvWalletClient(server, {
xPriv: exampleXPriv,
});

const userInfo = await client.GetUserInfo();
console.log('User XPub metadata:', userInfo.metadata);
console.log('User XPub (updated_at):', userInfo.updatedAt);

const updatedUserInfo = await client.UpdateUserMetadata({ some_metadata_2: 'example2' });
console.log('Updated User XPub metadata:', updatedUserInfo.metadata);
console.log('Updated User XPub (updated_at):', updatedUserInfo.updatedAt);
Loading