nexa-wallet-sdk 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -2,7 +2,6 @@ var $l50U0$libnexats = require("libnexa-ts");
2
2
  var $l50U0$bip39 = require("bip39");
3
3
  var $l50U0$vgrunnerelectrumcash = require("@vgrunner/electrum-cash");
4
4
  var $l50U0$jsbigdecimal = require("js-big-decimal");
5
- var $l50U0$walletcommssdk = require("wallet-comms-sdk");
6
5
 
7
6
 
8
7
  function $parcel$export(e, n, v, s) {
@@ -142,14 +141,11 @@ $parcel$export(module.exports, "AccountStore", () => $7fcf3b163a95e69a$export$2e
142
141
  $parcel$export(module.exports, "WalletTransactionCreator", () => $e1896e59040fa3c5$export$2e2bcd8739ae039);
143
142
  $parcel$export(module.exports, "WatchOnlyTransactionCreator", () => $2ce5b75d10954bb1$export$2e2bcd8739ae039);
144
143
  $parcel$export(module.exports, "rostrumProvider", () => $b5bfd17fdf06d231$export$eaa49f0478d81b9d);
145
- $parcel$export(module.exports, "WalletCommsIntegration", () => $23698d921173fdf9$export$11e896a2f3ae4119);
146
- $parcel$export(module.exports, "DAppCommsProvider", () => $4d217697e55d958e$export$80793d8292a1630a);
147
- $parcel$export(module.exports, "AUTO_APPROVE_CALLBACKS", () => $7af6fdca1cf5d9d6$export$618de809a659cb44);
148
144
  $parcel$export(module.exports, "SighashType", () => $l50U0$libnexats.SighashType);
149
145
  $parcel$export(module.exports, "AccountKeysUtils", () => $4d68f29c39c1a3e4$export$94f569bf4eb0f6f6);
150
146
  // @ts-ignore
151
147
  var $2dd241e44b9dc3c2$exports = {};
152
- $2dd241e44b9dc3c2$exports = JSON.parse("{\"name\":\"nexa-wallet-sdk\",\"version\":\"0.6.2\",\"type\":\"module\",\"source\":\"src/index.ts\",\"types\":\"dist/index.d.ts\",\"main\":\"dist/index.cjs\",\"module\":\"dist/index.mjs\",\"browser\":\"dist/index.web.mjs\",\"exports\":{\"types\":\"./dist/index.d.ts\",\"node\":{\"import\":\"./dist/index.mjs\",\"require\":\"./dist/index.cjs\"},\"browser\":\"./dist/index.web.mjs\",\"default\":\"./dist/index.mjs\"},\"scripts\":{\"build\":\"parcel build\",\"lint\":\"eslint .\",\"fix-lint\":\"eslint --fix .\",\"dev\":\"parcel watch\",\"test\":\"vitest run\",\"clean\":\"rm -rf dist .parcel-cache\",\"docs\":\"typedoc\",\"docs:serve\":\"typedoc && npx serve docs -l 8080\",\"docs:mkdocs\":\"typedoc && mkdocs serve\",\"docs:build\":\"typedoc && mkdocs build\",\"docs:setup\":\"./scripts/setup-docs.sh\",\"wallet-cli\":\"node examples/wallet-cli.cjs\"},\"repository\":{\"type\":\"git\",\"url\":\"git+ssh://git@gitlab.com/nexa/wallet-sdk-ts.git\"},\"keywords\":[\"nexa\",\"wallet\",\"web3\",\"crypto\",\"dapp\",\"walletcomms\",\"walletsdk\"],\"contributors\":[{\"name\":\"Dolaned\"},{\"name\":\"Griffith\"},{\"name\":\"Vgrunner\"},{\"name\":\"myendy\"}],\"author\":\"Dolaned\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://gitlab.com/nexa/wallet-sdk-ts/issues\"},\"homepage\":\"https://gitlab.com/nexa/wallet-sdk-ts#readme\",\"description\":\"Wallet SDK for the Nexa blockchain\",\"devDependencies\":{\"@parcel/bundler-library\":\"^2.16.0\",\"@parcel/packager-ts\":\"^2.15.4\",\"@parcel/transformer-typescript-types\":\"^2.15.4\",\"@types/lodash-es\":\"^4.17.12\",\"@types/node\":\"^22.13.1\",\"eslint\":\"^9.20.1\",\"parcel\":\"^2.15.4\",\"typedoc\":\"^0.28.7\",\"typedoc-plugin-markdown\":\"^4.7.0\",\"typedoc-plugin-rename-defaults\":\"^0.7.3\",\"typescript\":\"^5.8.3\",\"typescript-eslint\":\"^8.24.1\",\"vitest\":\"^3.0.8\"},\"targets\":{\"main\":{\"context\":\"node\",\"outputFormat\":\"commonjs\",\"distDir\":\"dist\",\"isLibrary\":true,\"includeNodeModules\":[\"lodash-es\"]},\"module\":{\"context\":\"node\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true},\"browser\":{\"context\":\"browser\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true}},\"dependencies\":{\"@vgrunner/electrum-cash\":\"^2.0.12\",\"bip39\":\"^3.1.0\",\"js-big-decimal\":\"^2.2.0\",\"libnexa-ts\":\"^2.1.0\",\"lodash-es\":\"^4.17.21\",\"prompt-sync\":\"^4.2.0\",\"wallet-comms-sdk\":\"^0.7.2\"},\"files\":[\"dist\"],\"directories\":{\"test\":\"tests\"},\"@parcel/resolver-default\":{\"packageExports\":true}}");
148
+ $2dd241e44b9dc3c2$exports = JSON.parse("{\"name\":\"nexa-wallet-sdk\",\"version\":\"0.7.0\",\"type\":\"module\",\"source\":\"src/index.ts\",\"types\":\"dist/index.d.ts\",\"main\":\"dist/index.cjs\",\"module\":\"dist/index.mjs\",\"browser\":\"dist/index.web.mjs\",\"exports\":{\"types\":\"./dist/index.d.ts\",\"node\":{\"import\":\"./dist/index.mjs\",\"require\":\"./dist/index.cjs\"},\"browser\":\"./dist/index.web.mjs\",\"default\":\"./dist/index.mjs\"},\"scripts\":{\"build\":\"parcel build\",\"lint\":\"eslint .\",\"fix-lint\":\"eslint --fix .\",\"dev\":\"parcel watch\",\"test\":\"vitest run\",\"clean\":\"rm -rf dist .parcel-cache\",\"docs\":\"typedoc\",\"docs:serve\":\"typedoc && npx serve docs -l 8080\",\"docs:mkdocs\":\"typedoc && mkdocs serve\",\"docs:build\":\"typedoc && mkdocs build\",\"docs:setup\":\"./scripts/setup-docs.sh\"},\"repository\":{\"type\":\"git\",\"url\":\"git+ssh://git@gitlab.com/nexa/wallet-sdk-ts.git\"},\"keywords\":[\"nexa\",\"wallet\",\"web3\",\"crypto\",\"dapp\",\"walletcomms\",\"walletsdk\"],\"contributors\":[{\"name\":\"Dolaned\"},{\"name\":\"Griffith\"},{\"name\":\"Vgrunner\"},{\"name\":\"myendy\"}],\"author\":\"Dolaned\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://gitlab.com/nexa/wallet-sdk-ts/issues\"},\"homepage\":\"https://gitlab.com/nexa/wallet-sdk-ts#readme\",\"description\":\"Wallet SDK for the Nexa blockchain\",\"devDependencies\":{\"@parcel/bundler-library\":\"^2.16.0\",\"@parcel/packager-ts\":\"^2.15.4\",\"@parcel/transformer-typescript-types\":\"^2.15.4\",\"@types/lodash-es\":\"^4.17.12\",\"@types/node\":\"^22.13.1\",\"eslint\":\"^9.20.1\",\"parcel\":\"^2.15.4\",\"typedoc\":\"^0.28.7\",\"typedoc-plugin-markdown\":\"^4.7.0\",\"typedoc-plugin-rename-defaults\":\"^0.7.3\",\"typescript\":\"^5.8.3\",\"typescript-eslint\":\"^8.24.1\",\"vitest\":\"^3.0.8\"},\"targets\":{\"main\":{\"context\":\"node\",\"outputFormat\":\"commonjs\",\"distDir\":\"dist\",\"isLibrary\":true,\"includeNodeModules\":[\"lodash-es\"]},\"module\":{\"context\":\"node\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true},\"browser\":{\"context\":\"browser\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true}},\"dependencies\":{\"@vgrunner/electrum-cash\":\"^2.0.12\",\"bip39\":\"^3.1.0\",\"js-big-decimal\":\"^2.2.0\",\"libnexa-ts\":\"^2.1.0\",\"lodash-es\":\"^4.17.21\",\"prompt-sync\":\"^4.2.0\"},\"files\":[\"dist\"],\"directories\":{\"test\":\"tests\"},\"@parcel/resolver-default\":{\"packageExports\":true}}");
153
149
 
154
150
 
155
151
 
@@ -3991,647 +3987,6 @@ class $f4ad400261a08cba$export$2e2bcd8739ae039 {
3991
3987
 
3992
3988
 
3993
3989
 
3994
-
3995
-
3996
- const $7af6fdca1cf5d9d6$export$618de809a659cb44 = {
3997
- approveTransaction: async ()=>true,
3998
- approveMessage: async ()=>true,
3999
- approveSendTransaction: async ()=>true,
4000
- approveNetworkSwitch: async ()=>true,
4001
- approveAddToken: async ()=>true,
4002
- approveConnection: async ()=>true
4003
- };
4004
-
4005
-
4006
- /**
4007
- * Extract all token outputs and amounts from transaction hex
4008
- * @param txHex - Transaction hex string
4009
- * @param network - Network to use for token address creation
4010
- * @returns Array of token outputs with tokenId and amount
4011
- */ const $23698d921173fdf9$var$getTokenOutputsFromTx = (txHex, network)=>{
4012
- const tokenOutputs = [];
4013
- try {
4014
- const transaction = new (0, $l50U0$libnexats.Transaction)(txHex);
4015
- for (const output of transaction.outputs)if (output.type !== 0 && output.scriptPubKey.chunks[0]?.opcodenum >= 32) {
4016
- const tokenIdHex = output.scriptPubKey.chunks[0].buf?.toString('hex');
4017
- if (tokenIdHex && output.scriptPubKey.chunks[1]?.buf) {
4018
- const tokenAddress = (0, $l50U0$libnexats.Address).fromObject({
4019
- data: tokenIdHex,
4020
- network: network.toString(),
4021
- type: (0, $l50U0$libnexats.AddressType).GroupIdAddress
4022
- });
4023
- if (tokenAddress !== null) {
4024
- const tokenAddressStr = tokenAddress.toString();
4025
- // Extract token amount
4026
- const tokenAmount = (0, $l50U0$libnexats.BNExtended).fromScriptNumBuffer(output.scriptPubKey.chunks[1].buf, false, 8).toBigInt();
4027
- tokenOutputs.push({
4028
- tokenId: tokenAddressStr,
4029
- amount: tokenAmount.toString()
4030
- });
4031
- }
4032
- }
4033
- }
4034
- } catch (error) {
4035
- console.warn('Failed to extract token data from transaction:', error);
4036
- }
4037
- return tokenOutputs;
4038
- };
4039
- class $23698d921173fdf9$export$11e896a2f3ae4119 {
4040
- constructor(wallet, approvalCallbacks){
4041
- this.provider = null;
4042
- this.currentAccount = null;
4043
- this.isConnected = false;
4044
- this.connectedDApp = null;
4045
- this.wallet = wallet;
4046
- this.approvalCallbacks = approvalCallbacks || (0, $7af6fdca1cf5d9d6$export$618de809a659cb44);
4047
- }
4048
- /**
4049
- * Set approval callbacks for handling user consent
4050
- */ setApprovalCallbacks(callbacks) {
4051
- this.approvalCallbacks = callbacks;
4052
- }
4053
- /**
4054
- * Connect to a dApp using a pairing URI
4055
- *
4056
- * This method will only use DApp accounts for security isolation.
4057
- * If no DApp account is provided, the first available one will be used or created.
4058
- *
4059
- * @param pairingURI - The pairing URI from the dApp (usually from QR code)
4060
- * @param dappAccount - Optional specific DApp account to use (defaults to first available)
4061
- * @returns Information about the connected dApp
4062
- */ async connect(pairingURI, dappAccount) {
4063
- if (this.isConnected) this.disconnect();
4064
- this.provider = new (0, $l50U0$walletcommssdk.DAppProvider)(pairingURI);
4065
- // Set up request handlers
4066
- this.setupHandlers();
4067
- // Connect to the relay server
4068
- await this.provider.connect();
4069
- // Get dApp information
4070
- const dAppInfo = await this.provider.getAppInfo();
4071
- // Request approval for connection if callback is provided
4072
- if (this.approvalCallbacks.approveConnection) {
4073
- const approved = await this.approvalCallbacks.approveConnection(dAppInfo);
4074
- if (!approved) {
4075
- this.provider.disconnect();
4076
- throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).RequestRejected, 'Connection rejected by user');
4077
- }
4078
- }
4079
- this.connectedDApp = dAppInfo;
4080
- // Use provided DApp account or get/create one
4081
- if (dappAccount) {
4082
- // Validate it's actually a DApp account
4083
- if (dappAccount.getAccountType() !== (0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).DAPP_ACCOUNT) throw new Error('Only DApp accounts can be used with WalletComms');
4084
- this.currentAccount = dappAccount;
4085
- } else this.currentAccount = await this.getOrCreateDAppAccount();
4086
- // Join the session with the DApp account address
4087
- const primaryAddress = this.currentAccount.getPrimaryAddressKey();
4088
- await this.provider.joinSession(primaryAddress.address);
4089
- this.isConnected = true;
4090
- return dAppInfo;
4091
- }
4092
- /**
4093
- * Get an existing DApp account or create a new one
4094
- *
4095
- * @returns A DApp account
4096
- */ async getOrCreateDAppAccount() {
4097
- // Get all DApp accounts using the new helper method
4098
- const dappAccounts = this.wallet.accountStore.getAccountsByType((0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).DAPP_ACCOUNT);
4099
- // Return first existing DApp account or create a new one
4100
- if (dappAccounts.length > 0) return dappAccounts[0];
4101
- // No DApp accounts exist, create one
4102
- return await this.wallet.newAccount((0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).DAPP_ACCOUNT);
4103
- }
4104
- /**
4105
- * Disconnect from the current dApp session
4106
- */ disconnect() {
4107
- if (this.provider) {
4108
- this.provider.disconnect();
4109
- this.provider = null;
4110
- }
4111
- this.isConnected = false;
4112
- this.currentAccount = null;
4113
- }
4114
- /**
4115
- * Set up handlers for dApp requests
4116
- */ setupHandlers() {
4117
- if (!this.provider) return;
4118
- // Handle message signing requests
4119
- this.provider.onSignMessage(async (request)=>{
4120
- try {
4121
- const account = this.getAccountByAddress(request.account);
4122
- if (!account) throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InvalidParams, `Account ${request.account} not found`);
4123
- // Request approval for message signing
4124
- if (this.approvalCallbacks.approveMessage && this.connectedDApp) {
4125
- const approvalDetails = {
4126
- dApp: this.connectedDApp,
4127
- account: request.account,
4128
- message: request.message,
4129
- messagePreview: request.message.length > 100 ? request.message.substring(0, 100) + '...' : request.message
4130
- };
4131
- const approved = await this.approvalCallbacks.approveMessage(approvalDetails);
4132
- if (!approved) throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).RequestRejected, 'Message signing rejected by user');
4133
- }
4134
- return this.wallet.signMessage(request.message, request.account);
4135
- } catch (error) {
4136
- throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InternalError, error instanceof Error ? error.message : 'Failed to sign message');
4137
- }
4138
- });
4139
- // Handle get account requests
4140
- this.provider.onGetAccount(async ()=>{
4141
- if (!this.currentAccount) throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InternalError, 'No account selected');
4142
- const primaryAddress = this.currentAccount.getPrimaryAddressKey();
4143
- return primaryAddress.address;
4144
- });
4145
- // Handle transaction signing requests
4146
- this.provider.onSignTransaction(async (request)=>{
4147
- try {
4148
- const account = this.getAccountByAddress(request.account);
4149
- if (!account) throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InvalidParams, `Account ${request.account} not found`);
4150
- // Request approval for transaction signing
4151
- if (this.approvalCallbacks.approveTransaction && this.connectedDApp) {
4152
- // Parse transaction to extract readable details
4153
- let totalAmount = 'Unknown';
4154
- let fees = 'Unknown';
4155
- try {
4156
- const tempBuilder = this.wallet.newTransaction(account, request.hex);
4157
- const tx = tempBuilder.transactionBuilder.build();
4158
- // Calculate total NEXA amount being sent (excluding change)
4159
- let nexaTotal = 0n;
4160
- for (const output of tx.outputs)if (output.value != BigInt((0, $l50U0$libnexats.Transaction).DUST_AMOUNT)) nexaTotal += output.value;
4161
- // Estimate fees
4162
- const estimatedFee = tx.estimateRequiredFee();
4163
- totalAmount = nexaTotal.toString();
4164
- fees = estimatedFee.toString();
4165
- } catch (error) {
4166
- // If parsing fails, keep default "Unknown" values
4167
- console.warn('Failed to parse transaction for approval details:', error);
4168
- }
4169
- // Extract token outputs from transaction hex
4170
- const tokenOutputs = $23698d921173fdf9$var$getTokenOutputsFromTx(request.hex, this.wallet.network);
4171
- const approvalDetails = {
4172
- dApp: this.connectedDApp,
4173
- account: request.account,
4174
- transactionHex: request.hex,
4175
- broadcast: request.broadcast || false,
4176
- totalAmount: totalAmount,
4177
- fees: fees,
4178
- tokenOutputs: tokenOutputs.length > 0 ? tokenOutputs : undefined
4179
- };
4180
- const approved = await this.approvalCallbacks.approveTransaction(approvalDetails);
4181
- if (!approved) throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).RequestRejected, 'Transaction signing rejected by user');
4182
- }
4183
- // Parse and sign the transaction
4184
- let txBuilder = this.wallet.newTransaction(account, request.hex);
4185
- txBuilder = txBuilder.sign();
4186
- const tx = await txBuilder.build();
4187
- // Broadcast if requested
4188
- if (request.broadcast) return await this.wallet.sendTransaction(tx); // Return just the txId string
4189
- return tx; // Return just the transaction hex string
4190
- } catch (error) {
4191
- throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InternalError, error instanceof Error ? error.message : 'Failed to sign transaction');
4192
- }
4193
- });
4194
- // Handle send transaction requests
4195
- this.provider.onSendTransaction(async (request)=>{
4196
- try {
4197
- const account = this.getAccountByAddress(request.from);
4198
- if (!account) throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InvalidParams, `Account ${request.from} not found`);
4199
- // Calculate total amount (request.to is now a single recipient object)
4200
- const totalAmount = !request.to.token ? BigInt(request.to.amount) : BigInt(0);
4201
- // Request approval for sending transaction
4202
- if (this.approvalCallbacks.approveSendTransaction && this.connectedDApp) {
4203
- const approvalDetails = {
4204
- dApp: this.connectedDApp,
4205
- fromAccount: request.from,
4206
- recipients: [
4207
- request.to
4208
- ],
4209
- totalAmount: totalAmount.toString(),
4210
- opReturn: request.data
4211
- };
4212
- const approved = await this.approvalCallbacks.approveSendTransaction(approvalDetails);
4213
- if (!approved) throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).RequestRejected, 'Send transaction rejected by user');
4214
- }
4215
- let txBuilder = this.wallet.newTransaction(account).onNetwork(this.wallet.network);
4216
- // Add recipient
4217
- if (request.to.token) txBuilder = txBuilder.sendToToken(request.to.address, request.to.amount, request.to.token);
4218
- else txBuilder = txBuilder.sendTo(request.to.address, request.to.amount);
4219
- // Add OP_RETURN data if provided
4220
- if (request.data) txBuilder = txBuilder.addOpReturn(request.data);
4221
- // Build and send the transaction
4222
- const tx = await txBuilder.populate().sign().build();
4223
- const txId = await this.wallet.sendTransaction(tx);
4224
- return txId; // Return just the txId string
4225
- } catch (error) {
4226
- throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InternalError, error instanceof Error ? error.message : 'Failed to send transaction');
4227
- }
4228
- });
4229
- // Handle network switching requests
4230
- this.provider.onSwitchNetwork(async (request)=>{
4231
- try {
4232
- // Validate network
4233
- const network = (0, $l50U0$libnexats.Networks).get(request.network);
4234
- if (!network) throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InvalidParams, `Unknown network: ${request.network}`);
4235
- // Reconnect to the new network
4236
- await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).connect(request.network);
4237
- return true;
4238
- } catch (error) {
4239
- throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InternalError, error instanceof Error ? error.message : 'Failed to switch network');
4240
- }
4241
- });
4242
- // Handle add token requests
4243
- this.provider.onAddToken(async (request)=>{
4244
- // This would need implementation based on how tokens are tracked
4245
- // For now, we'll acknowledge but not implement
4246
- console.log('Add token request:', request);
4247
- return true;
4248
- });
4249
- // Handle peer disconnect
4250
- this.provider.onPeerDisconnect(()=>{
4251
- console.log('DApp disconnected');
4252
- this.isConnected = false;
4253
- });
4254
- // Handle session deletion
4255
- this.provider.onSessionDelete(()=>{
4256
- console.log('Session deleted');
4257
- this.isConnected = false;
4258
- this.currentAccount = null;
4259
- this.connectedDApp = null;
4260
- });
4261
- // Handle connection close
4262
- this.provider.onClose(()=>{
4263
- console.log('Connection closed');
4264
- this.isConnected = false;
4265
- });
4266
- }
4267
- /**
4268
- * Get an account by its address
4269
- */ getAccountByAddress(address) {
4270
- const accounts = this.wallet.accountStore.listAccounts();
4271
- for (const [_, account] of accounts){
4272
- const addresses = account.getAddresses();
4273
- if (addresses.some((addr)=>addr.address === address)) return account;
4274
- }
4275
- return null;
4276
- }
4277
- /**
4278
- * Switch the active account
4279
- */ setActiveAccount(account) {
4280
- this.currentAccount = account;
4281
- }
4282
- /**
4283
- * Get the current active account
4284
- */ getActiveAccount() {
4285
- return this.currentAccount;
4286
- }
4287
- /**
4288
- * Check if connected to a dApp
4289
- */ isConnectedToDApp() {
4290
- return this.isConnected;
4291
- }
4292
- /**
4293
- * Get the current session details
4294
- */ getSessionInfo() {
4295
- if (!this.provider) return null;
4296
- return this.provider.getSessionInfo();
4297
- }
4298
- /**
4299
- * Revoke/terminate the current session
4300
- */ async revokeSession() {
4301
- if (!this.provider) throw new Error('Not connected to a dApp');
4302
- await this.provider.revokeSession();
4303
- this.disconnect();
4304
- }
4305
- }
4306
-
4307
-
4308
-
4309
-
4310
-
4311
- class $4d217697e55d958e$export$80793d8292a1630a {
4312
- /**
4313
- * Creates a new DAppCommsProvider instance
4314
- * @param relayUrl The WalletComms relay server URL
4315
- * @param dAppInfo Information about your dApp
4316
- * @param network Optional network (defaults to mainnet)
4317
- */ constructor(relayUrl, dAppInfo, network = 'mainnet'){
4318
- this.watchOnlyWallet = null;
4319
- this.connectedWalletAddress = null;
4320
- this.currentNetwork = 'mainnet';
4321
- this.provider = new (0, $l50U0$walletcommssdk.WalletProvider)(relayUrl, dAppInfo);
4322
- this.currentNetwork = network;
4323
- }
4324
- /**
4325
- * Connect to the WalletComms relay server
4326
- * @returns Promise resolving when connected
4327
- */ async connect() {
4328
- await this.provider.connect();
4329
- // Connect to the appropriate network
4330
- await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).connect(this.currentNetwork);
4331
- }
4332
- /**
4333
- * Get the pairing URI for QR code display
4334
- * @returns The pairing URI string
4335
- */ getPairingURI() {
4336
- return this.provider.getPairingURI();
4337
- }
4338
- /**
4339
- * Wait for a wallet to connect
4340
- * @param timeout Timeout in milliseconds (default 30000)
4341
- * @returns Promise resolving to the wallet address
4342
- */ async waitForWallet(timeout = 30000) {
4343
- try {
4344
- // Use the built-in waitForWallet method from WalletProvider
4345
- const walletAddress = await this.provider.waitForWallet(timeout);
4346
- this.connectedWalletAddress = walletAddress;
4347
- // Create WatchOnlyWallet with the connected address
4348
- this.watchOnlyWallet = new (0, $f4ad400261a08cba$export$2e2bcd8739ae039)([
4349
- {
4350
- address: walletAddress
4351
- }
4352
- ], this.currentNetwork);
4353
- return walletAddress;
4354
- } catch (error) {
4355
- throw new Error(`Failed to connect wallet: ${error instanceof Error ? error.message : 'Unknown error'}`);
4356
- }
4357
- }
4358
- /**
4359
- * Send NEXA to an address
4360
- * @param toAddress Destination address
4361
- * @param amount Amount in satoshis (as string)
4362
- * @param opReturnData Optional OP_RETURN data
4363
- * @param broadcast Whether to broadcast immediately (default true)
4364
- * @returns Promise resolving to transaction ID or signed hex
4365
- */ async sendTransaction(toAddress, amount, opReturnData, broadcast = true) {
4366
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4367
- // Create unsigned transaction using WatchOnlyWallet
4368
- let txBuilder = this.watchOnlyWallet.newTransaction().sendTo(toAddress, amount);
4369
- // Add OP_RETURN data if provided
4370
- if (opReturnData) txBuilder = txBuilder.addOpReturn(opReturnData);
4371
- // Populate and build unsigned transaction
4372
- const unsignedTx = await txBuilder.populate().build();
4373
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4374
- }
4375
- /**
4376
- * Send tokens to an address
4377
- * @param toAddress Destination address
4378
- * @param amount Amount of tokens (as string)
4379
- * @param tokenId Token ID
4380
- * @param opReturnData Optional OP_RETURN data
4381
- * @param broadcast Whether to broadcast immediately (default true)
4382
- * @returns Promise resolving to transaction ID or signed hex
4383
- */ async sendTokenTransaction(toAddress, amount, tokenId, opReturnData, broadcast = true) {
4384
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4385
- // Create unsigned token transaction
4386
- let txBuilder = this.watchOnlyWallet.newTransaction().sendToToken(toAddress, amount, tokenId);
4387
- // Add OP_RETURN data if provided
4388
- if (opReturnData) txBuilder = txBuilder.addOpReturn(opReturnData);
4389
- // Populate and build unsigned transaction
4390
- const unsignedTx = await txBuilder.populate().build();
4391
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4392
- }
4393
- /**
4394
- * Create and mint a new token
4395
- * @param name Token name
4396
- * @param ticker Token ticker symbol
4397
- * @param decimals Number of decimal places
4398
- * @param docUrl URL to token documentation
4399
- * @param docHash Hash of token documentation
4400
- * @param broadcast Whether to broadcast immediately (default true)
4401
- * @returns Promise resolving to transaction ID or signed hex
4402
- */ async createToken(name, ticker, decimals, docUrl, docHash, broadcast = true) {
4403
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4404
- // Create token creation transaction
4405
- const unsignedTx = await this.watchOnlyWallet.newTransaction().token(name, ticker, decimals, docUrl, docHash).populate().build();
4406
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4407
- }
4408
- /**
4409
- * Create and mint a new NFT collection
4410
- * @param name Collection name
4411
- * @param ticker Collection ticker symbol
4412
- * @param docUrl URL to collection documentation
4413
- * @param docHash Hash of collection documentation
4414
- * @param broadcast Whether to broadcast immediately (default true)
4415
- * @returns Promise resolving to transaction ID or signed hex
4416
- */ async createCollection(name, ticker, docUrl, docHash, broadcast = true) {
4417
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4418
- // Create collection creation transaction
4419
- const unsignedTx = await this.watchOnlyWallet.newTransaction().collection(name, ticker, docUrl, docHash).populate().build();
4420
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4421
- }
4422
- /**
4423
- * Create and mint an NFT within a collection
4424
- * @param parentCollection Parent collection token ID
4425
- * @param zipUrl URL to NFT content ZIP file
4426
- * @param zipHash Hash of NFT content ZIP file
4427
- * @param broadcast Whether to broadcast immediately (default true)
4428
- * @returns Promise resolving to transaction ID or signed hex
4429
- */ async createNFT(parentCollection, zipUrl, zipHash, broadcast = true) {
4430
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4431
- // Create NFT creation transaction
4432
- const unsignedTx = await this.watchOnlyWallet.newTransaction().nft(parentCollection, zipUrl, zipHash).populate().build();
4433
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4434
- }
4435
- /**
4436
- * Create and mint an SFT (Semi-Fungible Token) within a collection with specified quantity
4437
- * @param parentCollection Parent collection token ID
4438
- * @param zipUrl URL to SFT content ZIP file
4439
- * @param zipHash Hash of SFT content ZIP file
4440
- * @param quantity Quantity of SFTs to create
4441
- * @param broadcast Whether to broadcast immediately (default true)
4442
- * @returns Promise resolving to transaction ID or signed hex
4443
- */ async createSFT(parentCollection, zipUrl, zipHash, quantity, broadcast = true) {
4444
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4445
- // Create SFT creation transaction
4446
- const unsignedTx = await this.watchOnlyWallet.newTransaction().sft(parentCollection, zipUrl, zipHash, quantity).populate().build();
4447
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4448
- }
4449
- /**
4450
- * Sign an arbitrary unsigned transaction
4451
- * @param unsignedTx Unsigned transaction hex string
4452
- * @param sighashSpec Optional sighash specification for selective signing
4453
- * @param broadcast Whether to broadcast immediately (default false)
4454
- * @returns Promise resolving to transaction ID (if broadcast) or signed hex
4455
- */ async signTransaction(unsignedTx, sighashSpec, broadcast = false) {
4456
- if (!this.connectedWalletAddress) throw new Error('No wallet connected');
4457
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4458
- }
4459
- /**
4460
- * Build an unsigned transaction without signing
4461
- * @param toAddress Destination address
4462
- * @param amount Amount in satoshis (as string)
4463
- * @param tokenId Optional token ID for token transfers
4464
- * @param opReturnData Optional OP_RETURN data
4465
- * @returns Promise resolving to unsigned transaction hex
4466
- */ async buildTransaction(toAddress, amount, tokenId, opReturnData) {
4467
- if (!this.watchOnlyWallet) throw new Error('No wallet connected');
4468
- let txBuilder = this.watchOnlyWallet.newTransaction();
4469
- if (tokenId) txBuilder = txBuilder.sendToToken(toAddress, amount, tokenId);
4470
- else txBuilder = txBuilder.sendTo(toAddress, amount);
4471
- if (opReturnData) txBuilder = txBuilder.addOpReturn(opReturnData);
4472
- return await txBuilder.populate().build();
4473
- }
4474
- /**
4475
- * Build an unsigned token creation transaction
4476
- * @param name Token name
4477
- * @param ticker Token ticker symbol
4478
- * @param decimals Number of decimal places
4479
- * @param docUrl URL to token documentation
4480
- * @param docHash Hash of token documentation
4481
- * @returns Promise resolving to unsigned transaction hex
4482
- */ async buildTokenCreation(name, ticker, decimals, docUrl, docHash) {
4483
- if (!this.watchOnlyWallet) throw new Error('No wallet connected');
4484
- return await this.watchOnlyWallet.newTransaction().token(name, ticker, decimals, docUrl, docHash).populate().build();
4485
- }
4486
- /**
4487
- * Build an unsigned collection creation transaction
4488
- * @param name Collection name
4489
- * @param ticker Collection ticker symbol
4490
- * @param docUrl URL to collection documentation
4491
- * @param docHash Hash of collection documentation
4492
- * @returns Promise resolving to unsigned transaction hex
4493
- */ async buildCollectionCreation(name, ticker, docUrl, docHash) {
4494
- if (!this.watchOnlyWallet) throw new Error('No wallet connected');
4495
- return await this.watchOnlyWallet.newTransaction().collection(name, ticker, docUrl, docHash).populate().build();
4496
- }
4497
- /**
4498
- * Build an unsigned NFT creation transaction
4499
- * @param parentCollection Parent collection token ID
4500
- * @param zipUrl URL to NFT content ZIP file
4501
- * @param zipHash Hash of NFT content ZIP file
4502
- * @returns Promise resolving to unsigned transaction hex
4503
- */ async buildNFTCreation(parentCollection, zipUrl, zipHash) {
4504
- if (!this.watchOnlyWallet) throw new Error('No wallet connected');
4505
- return await this.watchOnlyWallet.newTransaction().nft(parentCollection, zipUrl, zipHash).populate().build();
4506
- }
4507
- /**
4508
- * Build an unsigned SFT creation transaction
4509
- * @param parentCollection Parent collection token ID
4510
- * @param zipUrl URL to SFT content ZIP file
4511
- * @param zipHash Hash of SFT content ZIP file
4512
- * @param quantity Quantity of SFTs to create
4513
- * @returns Promise resolving to unsigned transaction hex
4514
- */ async buildSFTCreation(parentCollection, zipUrl, zipHash, quantity) {
4515
- if (!this.watchOnlyWallet) throw new Error('No wallet connected');
4516
- return await this.watchOnlyWallet.newTransaction().sft(parentCollection, zipUrl, zipHash, quantity).populate().build();
4517
- }
4518
- /**
4519
- * Initialize WatchOnlyWallet with multiple addresses
4520
- * @param addresses Array of addresses to watch
4521
- */ initializeWatchOnly(addresses) {
4522
- this.watchOnlyWallet = new (0, $f4ad400261a08cba$export$2e2bcd8739ae039)(addresses.map((addr)=>({
4523
- address: addr
4524
- })), this.currentNetwork);
4525
- }
4526
- /**
4527
- * Create a custom unsigned transaction
4528
- * @param txBuilder Function that configures the transaction builder
4529
- * @param sighashSpec Optional sighash specification for selective signing
4530
- * @param broadcast Whether to broadcast immediately (default true)
4531
- * @returns Promise resolving to transaction ID or signed hex
4532
- */ async createCustomTransaction(txBuilder, sighashSpec, broadcast = true) {
4533
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4534
- // Create custom transaction using provided builder function
4535
- const builder = this.watchOnlyWallet.newTransaction();
4536
- const configuredBuilder = txBuilder(builder);
4537
- const unsignedTx = await configuredBuilder.populate().build();
4538
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4539
- }
4540
- /**
4541
- * Sign a message with the connected wallet
4542
- * @param message Message to sign
4543
- * @returns Promise resolving to the signature
4544
- */ async signMessage(message) {
4545
- if (!this.connectedWalletAddress) throw new Error('No wallet connected');
4546
- return await this.provider.signMessage(this.connectedWalletAddress, message);
4547
- }
4548
- /**
4549
- * Switch to a different network
4550
- * @param network Network name or identifier
4551
- * @returns Promise resolving when network is switched
4552
- */ async switchNetwork(network) {
4553
- await this.provider.switchNetwork(network);
4554
- this.currentNetwork = network;
4555
- // Reconnect rostrum provider to new network
4556
- await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).connect(network);
4557
- // Update watch-only wallet network if connected
4558
- if (this.watchOnlyWallet && this.connectedWalletAddress) this.watchOnlyWallet = new (0, $f4ad400261a08cba$export$2e2bcd8739ae039)([
4559
- {
4560
- address: this.connectedWalletAddress
4561
- }
4562
- ], network);
4563
- }
4564
- /**
4565
- * Get the currently connected wallet address
4566
- * @returns Wallet address or null if not connected
4567
- */ getConnectedWallet() {
4568
- return this.connectedWalletAddress;
4569
- }
4570
- /**
4571
- * Check if a wallet is currently connected
4572
- * @returns True if wallet is connected
4573
- */ isConnected() {
4574
- return this.connectedWalletAddress !== null;
4575
- }
4576
- /**
4577
- * Get the current network
4578
- * @returns Current network identifier
4579
- */ getCurrentNetwork() {
4580
- return this.currentNetwork;
4581
- }
4582
- /**
4583
- * Get the underlying WatchOnlyWallet instance
4584
- * @returns WatchOnlyWallet instance or null if not connected
4585
- */ getWatchOnlyWallet() {
4586
- return this.watchOnlyWallet;
4587
- }
4588
- /**
4589
- * Disconnect from the wallet
4590
- */ disconnect() {
4591
- this.provider.disconnect();
4592
- this.watchOnlyWallet = null;
4593
- this.connectedWalletAddress = null;
4594
- }
4595
- /**
4596
- * Set up event listeners for wallet events
4597
- * @param event Event name
4598
- * @param callback Event callback
4599
- */ on(event, callback) {
4600
- this.provider.on(event, callback);
4601
- }
4602
- /**
4603
- * Remove event listeners
4604
- * @param event Event name
4605
- */ off(event) {
4606
- this.provider.off(event);
4607
- }
4608
- /**
4609
- * Set up wallet disconnect event listener
4610
- * @param callback Function to call when wallet disconnects
4611
- */ onWalletDisconnect(callback) {
4612
- this.provider.onPeerDisconnect(()=>{
4613
- this.watchOnlyWallet = null;
4614
- this.connectedWalletAddress = null;
4615
- callback();
4616
- });
4617
- }
4618
- /**
4619
- * Set up connection close event listener
4620
- * @param callback Function to call when connection closes
4621
- */ onConnectionClose(callback) {
4622
- this.provider.onClose(()=>{
4623
- this.watchOnlyWallet = null;
4624
- this.connectedWalletAddress = null;
4625
- callback();
4626
- });
4627
- }
4628
- }
4629
- var $4d217697e55d958e$export$2e2bcd8739ae039 = $4d217697e55d958e$export$80793d8292a1630a;
4630
-
4631
-
4632
-
4633
-
4634
-
4635
3990
  /**
4636
3991
  * Guards against multiple instances of the wallet SDK being loaded.
4637
3992
  * This prevents conflicts and ensures only one version is active at a time.