diff --git a/packages/sdk/src/transactions/InscriberV2.ts b/packages/sdk/src/transactions/InscriberV2.ts index 6bd60209..08c1450b 100644 --- a/packages/sdk/src/transactions/InscriberV2.ts +++ b/packages/sdk/src/transactions/InscriberV2.ts @@ -31,6 +31,7 @@ export class InscriberV2 extends PSBTBuilder { private recovery = false private recoverAmount = 0 private previewMode = false + private isStandard = true readonly metaInscriptions: EnvelopeOpts[] readonly inscriptions: EnvelopeOpts[] @@ -56,7 +57,8 @@ export class InscriberV2 extends PSBTBuilder { taptreeVersion, datasource, metaInscriptions, - inscriptions + inscriptions, + isStandard }: InscriberV2ArgOptions) { super({ address, @@ -74,6 +76,7 @@ export class InscriberV2 extends PSBTBuilder { this.taptreeVersion = taptreeVersion this.metaInscriptions = metaInscriptions ?? [] this.inscriptions = inscriptions ?? [] + this.isStandard = isStandard ?? true } get data() { @@ -276,6 +279,13 @@ export class InscriberV2 extends PSBTBuilder { await this.calculateNetworkFeeUsingPreviewMode() + if (this.isStandard) { + // max weight of a tx is 400,000 WU https://github.com/bitcoin/bitcoin/blob/d908877c4774c2456eed09167a5f382758e4a8a6/src/policy/policy.h#L26-L27 + if (this.weight > 400_000) { + throw new OrditSDKError("Transaction exceeds maximum weight") + } + } + this.commitAddress = this.payment.address! return { address: this.payment.address!, @@ -355,6 +365,7 @@ export type InscriberV2ArgOptions = { taptreeVersion?: TaptreeVersion outputs?: Outputs datasource?: BaseDatasource + isStandard?: boolean } type Outputs = Array<{ address: string; value: number }> diff --git a/packages/sdk/src/wallet/Ordit.ts b/packages/sdk/src/wallet/Ordit.ts index 28b9fcb8..6ea6dac2 100644 --- a/packages/sdk/src/wallet/Ordit.ts +++ b/packages/sdk/src/wallet/Ordit.ts @@ -10,13 +10,15 @@ import ECPairFactory, { ECPairInterface } from "ecpair" import { Account, AddressFormats, - addressNameToType, DerivationIndex, + addressNameToType, + DerivationIndex, getAccountDataFromHdNode, getAddressesFromPublicKey, getAllAccountsFromHdNode, getNetwork, mintFromCollection, - publishCollection, SigningMessageOptions, + publishCollection, + SigningMessageOptions, tweakSigner } from ".." import { Network } from "../config/types" @@ -37,7 +39,16 @@ export class Ordit { selectedAddressType: AddressFormats | undefined selectedAddress: string | undefined - constructor({ wif, seed, privateKey, bip39, network = "testnet", type = "legacy", account = 0, addressIndex = 0 }: WalletOptions) { + constructor({ + wif, + seed, + privateKey, + bip39, + network = "testnet", + type = "legacy", + account = 0, + addressIndex = 0 + }: WalletOptions) { this.#network = network const networkObj = getNetwork(network) const format = addressNameToType[type] @@ -102,8 +113,12 @@ export class Ordit { if (!this.#initialized || !this.allAddresses.length) { throw new OrditSDKError("Wallet not fully initialized.") } - return this.allAddresses.find((address) => address.format === type && address.derivationPath.account === derivationIndex.accountIndex - && address.derivationPath.addressIndex === derivationIndex.addressIndex); + return this.allAddresses.find( + (address) => + address.format === type && + address.derivationPath.account === derivationIndex.accountIndex && + address.derivationPath.addressIndex === derivationIndex.addressIndex + ) } getAllAddresses() { @@ -114,17 +129,20 @@ export class Ordit { return this.allAddresses } - setDefaultAddress(type: AddressFormats, { accountIndex = 0, addressIndex = 0 }: DerivationIndex) { + setDefaultAddress( + type: AddressFormats, + { accountIndex, addressIndex }: DerivationIndex = { accountIndex: 0, addressIndex: 0 } + ) { if (this.selectedAddressType === type) return - let addressToSelect: Account; + let addressToSelect: Account const account = this.getAddressByType(type, { accountIndex, addressIndex }) as Account if (!account) { - addressToSelect = this.generateAddress(type, accountIndex, addressIndex); + addressToSelect = this.generateAddress(type, accountIndex, addressIndex) // Push to current list of addresses - this.allAddresses.push(addressToSelect); + this.allAddresses.push(addressToSelect) } else { - addressToSelect = account; + addressToSelect = account } if (!addressToSelect) @@ -237,9 +255,12 @@ export class Ordit { signMessage(message: string, type?: AddressFormats, opts?: SigningMessageOptions) { const addressType = type || this.selectedAddressType - const accountIndexToSign: number = opts?.accountIndex === undefined ? 0 : opts?.accountIndex; - const addressIndexToSign: number = opts?.addressIndex === undefined ? 0 : opts?.addressIndex; - const node = this.getAddressByType(addressType!, { accountIndex: accountIndexToSign, addressIndex: addressIndexToSign }) as Account + const accountIndexToSign: number = opts?.accountIndex === undefined ? 0 : opts?.accountIndex + const addressIndexToSign: number = opts?.addressIndex === undefined ? 0 : opts?.addressIndex + const node = this.getAddressByType(addressType!, { + accountIndex: accountIndexToSign, + addressIndex: addressIndexToSign + }) as Account const signature = AddressUtils.isP2PKH(node.address!) ? sign(message, node.child.privateKey!) : Signer.sign(node.child.toWIF(), node.address!, message, getNetwork(this.#network)) @@ -270,8 +291,8 @@ export type WalletOptions = { bip39?: string network?: Network type?: AddressFormats - account?: number; - addressIndex?: number; + account?: number + addressIndex?: number } export type Address = ReturnType[0]