From 3c33ea42f084d255d65f3d4bef1c3d09152077b9 Mon Sep 17 00:00:00 2001 From: David Kaplan Date: Wed, 25 Sep 2024 15:37:16 -0400 Subject: [PATCH 1/4] chore(sdk-core): add txFormat to the interface TICKET: BTC-1501 --- .../src/bitgo/inscriptionBuilder/iInscriptionBuilder.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/sdk-core/src/bitgo/inscriptionBuilder/iInscriptionBuilder.ts b/modules/sdk-core/src/bitgo/inscriptionBuilder/iInscriptionBuilder.ts index 159f5510b4..4c9bb219e7 100644 --- a/modules/sdk-core/src/bitgo/inscriptionBuilder/iInscriptionBuilder.ts +++ b/modules/sdk-core/src/bitgo/inscriptionBuilder/iInscriptionBuilder.ts @@ -56,6 +56,7 @@ export interface IInscriptionBuilder { cosigner, inscriptionConstraints, changeAddressType, + txFormat, }: { signer: utxolib.bitgo.KeyName; cosigner: utxolib.bitgo.KeyName; @@ -65,6 +66,7 @@ export interface IInscriptionBuilder { maxInscriptionOutput?: bigint; }; changeAddressType: utxolib.bitgo.outputScripts.ScriptType2Of3; + txFormat?: 'psbt' | 'legacy'; } ): Promise; From 2e086101eedfb221f22d8f70c6223b321b2b7e8c Mon Sep 17 00:00:00 2001 From: David Kaplan Date: Wed, 25 Sep 2024 15:40:52 -0400 Subject: [PATCH 2/4] chore(sdk-core): add example to moving an ordinal TICKET: BTC-1501 --- .../btc/ordinals/move-individual-ordinal.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 examples/ts/btc/ordinals/move-individual-ordinal.ts diff --git a/examples/ts/btc/ordinals/move-individual-ordinal.ts b/examples/ts/btc/ordinals/move-individual-ordinal.ts new file mode 100644 index 0000000000..5eacfdc40b --- /dev/null +++ b/examples/ts/btc/ordinals/move-individual-ordinal.ts @@ -0,0 +1,50 @@ +/** + * Transfer an individual ordinal from one address to another + * + * Copyright 2024 BitGo, Inc. All Rights Reserved. + */ + +const BitGoJS = require('bitgo'); + +// change this to env: 'prod' when you are ready for production +const env = 'test'; +// change coin to 'btc' when working with production +const coin = env === 'test' ? 'tbtc' : 'btc'; + +const bitgo = new BitGoJS.BitGo({ env }); + +// set your access token and walletPassphrase here +const accessToken = ''; +const walletPassphrase = ''; + +// set your wallet ID here +const walletId = ''; + +// The location of the ordinal you want to send {txid}:{vout}:{offset} +// Background about how ordinals work here: https://docs.ordinals.com/overview.html +const satPoint = ''; + +// set where you are sending the ordinal +const recipient = ''; + +// set the fee rate for the transaction in Satoshis per KB +const feeRateSatKb = 1000; + +async function transferIndividualOrdinal() { + // Authenticate and get wallet + await bitgo.authenticateWithAccessToken({ accessToken }); + const wallet = await bitgo.coin(coin).wallets().get({ id: walletId }); + + // Instantiate the transaction builder that will be used to send the particular ordinal + // We need to use this specific transaction builder so that we are safely extracting the exact ordinal. + const inscriptionBuilder = bitgo.coin(coin).getInscriptionBuilder(wallet); + + // Build the transaction to send the ordinal + // Note that you can configure the structure of the transaction by passing in additional parameters + const buildResult = await inscriptionBuilder.prepareTransfer(satPoint, recipient, feeRateSatKb, {}); + + const sent = await inscriptionBuilder.signAndSendTransfer(walletPassphrase, buildResult); + console.log('sent ' + JSON.stringify(sent, null, 2)); +} + +transferIndividualOrdinal().catch(console.error); From e1b44f81cb28a4d8a3eec52c0383b38573c40eff Mon Sep 17 00:00:00 2001 From: David Kaplan Date: Wed, 25 Sep 2024 15:43:36 -0400 Subject: [PATCH 3/4] chore: move custodial lighting examples to deprecated TICKET: BTC-1501 --- examples/README.md | 9 --------- .../custodialLightning}/check-lightning-balance.ts | 0 .../custodialLightning}/create-lightning-invoice.ts | 0 .../custodialLightning}/make-lightning-deposit.ts | 0 .../custodialLightning}/make-lightning-payment.ts | 0 .../custodialLightning}/pay-lnurl-request.ts | 0 .../custodialLightning}/withdraw-lightning-balance.ts | 0 7 files changed, 9 deletions(-) rename examples/ts/btc/{ => deprecated/custodialLightning}/check-lightning-balance.ts (100%) rename examples/ts/btc/{ => deprecated/custodialLightning}/create-lightning-invoice.ts (100%) rename examples/ts/btc/{ => deprecated/custodialLightning}/make-lightning-deposit.ts (100%) rename examples/ts/btc/{ => deprecated/custodialLightning}/make-lightning-payment.ts (100%) rename examples/ts/btc/{ => deprecated/custodialLightning}/pay-lnurl-request.ts (100%) rename examples/ts/btc/{ => deprecated/custodialLightning}/withdraw-lightning-balance.ts (100%) diff --git a/examples/README.md b/examples/README.md index d713af50ac..49f7fd98a7 100644 --- a/examples/README.md +++ b/examples/README.md @@ -41,15 +41,6 @@ In this directory, you can find examples on how to use the BitGoJS SDK with Type - [Enable Token](./ts/algo/enable-token.ts) - [Transaction with emergency param](./ts/algo/transaction-with-emergency-param.ts) -### Bitcoin Lightning (BTC) - -- [Check Lightning Balance](./ts/btc/check-lightning-balance.ts) -- [Create Lightning Invoice](./ts/btc/create-lightning-invoice.ts) -- [Withdraw Lightning Balance](./ts/btc/withdraw-lightning-balance.ts) -- [Make Lightning Deposit](./ts/btc/make-lightning-deposit.ts) -- [Make Lightning Payment](./ts/btc/make-lightning-payment.ts) -- [Pay LNURL Request](./ts/btc/pay-lnurl-request.ts) - ### Ethereum (ETH) - [Create Wallet Address](./ts/eth/create-wallet-address.ts) diff --git a/examples/ts/btc/check-lightning-balance.ts b/examples/ts/btc/deprecated/custodialLightning/check-lightning-balance.ts similarity index 100% rename from examples/ts/btc/check-lightning-balance.ts rename to examples/ts/btc/deprecated/custodialLightning/check-lightning-balance.ts diff --git a/examples/ts/btc/create-lightning-invoice.ts b/examples/ts/btc/deprecated/custodialLightning/create-lightning-invoice.ts similarity index 100% rename from examples/ts/btc/create-lightning-invoice.ts rename to examples/ts/btc/deprecated/custodialLightning/create-lightning-invoice.ts diff --git a/examples/ts/btc/make-lightning-deposit.ts b/examples/ts/btc/deprecated/custodialLightning/make-lightning-deposit.ts similarity index 100% rename from examples/ts/btc/make-lightning-deposit.ts rename to examples/ts/btc/deprecated/custodialLightning/make-lightning-deposit.ts diff --git a/examples/ts/btc/make-lightning-payment.ts b/examples/ts/btc/deprecated/custodialLightning/make-lightning-payment.ts similarity index 100% rename from examples/ts/btc/make-lightning-payment.ts rename to examples/ts/btc/deprecated/custodialLightning/make-lightning-payment.ts diff --git a/examples/ts/btc/pay-lnurl-request.ts b/examples/ts/btc/deprecated/custodialLightning/pay-lnurl-request.ts similarity index 100% rename from examples/ts/btc/pay-lnurl-request.ts rename to examples/ts/btc/deprecated/custodialLightning/pay-lnurl-request.ts diff --git a/examples/ts/btc/withdraw-lightning-balance.ts b/examples/ts/btc/deprecated/custodialLightning/withdraw-lightning-balance.ts similarity index 100% rename from examples/ts/btc/withdraw-lightning-balance.ts rename to examples/ts/btc/deprecated/custodialLightning/withdraw-lightning-balance.ts From b2d00c1969be369cbb4fc5552d8f5679836efe4c Mon Sep 17 00:00:00 2001 From: David Kaplan Date: Wed, 25 Sep 2024 15:59:35 -0400 Subject: [PATCH 4/4] chore: add unspent reservation example TICKET: BTC-1501 --- examples/ts/reserve-unspents.ts | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 examples/ts/reserve-unspents.ts diff --git a/examples/ts/reserve-unspents.ts b/examples/ts/reserve-unspents.ts new file mode 100644 index 0000000000..02a82d38dc --- /dev/null +++ b/examples/ts/reserve-unspents.ts @@ -0,0 +1,57 @@ +/** + * Manage unspent reservations on your wallet + * + * Copyright 2024 BitGo, Inc. All Rights Reserved. + */ + +const BitGoJS = require('modules/bitgo'); + +// change this to env: 'prod' when you are ready for production +const env = 'test'; +// change coin to 'btc' when working with production +const coin = env === 'test' ? 'tbtc' : 'btc'; + +const bitgo = new BitGoJS.BitGo({ env }); + +// set your access token here +const accessToken = ''; + +// set the unspent IDs to manage the reservations of +const unspentIds = ['', '']; + +// set the expire time for the reservation (use 'never' to freeze) +const expireTime = ''; + +async function createUnspentReservation() { + bitgo.authenticateWithAccessToken({ accessToken }); + const wallet = await bitgo.coin(coin).wallets().get({ id: walletId }); + + const reserveResult = await wallet.manageUnspentReservations({ + create: { unspentIds, expireTime: 'never' }, + }); + console.log('reserved ' + JSON.stringify(reserveResult, null, 2)); +} + +async function modifyUnspentReservation() { + bitgo.authenticateWithAccessToken({ accessToken }); + const wallet = await bitgo.coin(coin).wallets().get({ id: walletId }); + + const reserveResult = await wallet.manageUnspentReservations({ + modify: { unspentIds, changes: { expireTime } }, + }); + console.log('modified ' + JSON.stringify(reserveResult, null, 2)); +} + +async function releaseUnspentReservation() { + bitgo.authenticateWithAccessToken({ accessToken }); + const wallet = await bitgo.coin(coin).wallets().get({ id: walletId }); + + const reserveResult = await wallet.manageUnspentReservations({ + delete: { id: unspentIds[0] }, + }); + console.log('released ' + JSON.stringify(reserveResult, null, 2)); +} + +// createUnspentReservation().catch(console.error); +// modifyUnspentReservation().catch(console.error); +// releaseUnspentReservation().catch(console.error);