nexa-wallet-sdk 0.6.3 → 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.3\",\"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,711 +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
- * Create a new session on the relay server
4326
- * @param timeout Timeout in milliseconds (default 10000)
4327
- * @returns Promise resolving when session is created
4328
- */ async createSession(timeout = 10000) {
4329
- await this.provider.createSession(timeout);
4330
- }
4331
- /**
4332
- * Connect to the WalletComms relay server and create a session
4333
- * @returns Promise resolving when connected
4334
- */ async connect() {
4335
- await this.provider.connect();
4336
- await this.provider.createSession();
4337
- // Connect to the appropriate network
4338
- await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).connect(this.currentNetwork);
4339
- }
4340
- /**
4341
- * Rejoin an existing session
4342
- * @param timeout Timeout in milliseconds (default 10000)
4343
- * @returns Promise resolving to true if successfully rejoined
4344
- */ async rejoinSession(timeout = 10000) {
4345
- return await this.provider.rejoinSession(timeout);
4346
- }
4347
- /**
4348
- * Get the pairing URI for QR code display
4349
- * @returns The pairing URI string
4350
- */ getPairingURI() {
4351
- return this.provider.getPairingURI();
4352
- }
4353
- /**
4354
- * Cancel waiting for wallet connection
4355
- */ cancelWaitForWallet() {
4356
- this.provider.cancelWaitForWallet();
4357
- }
4358
- /**
4359
- * Wait for a wallet to connect
4360
- * @param timeout Timeout in milliseconds (default 30000)
4361
- * @returns Promise resolving to the wallet address
4362
- */ async waitForWallet(timeout = 30000) {
4363
- try {
4364
- // Use the built-in waitForWallet method from WalletProvider
4365
- const walletAddress = await this.provider.waitForWallet(timeout);
4366
- this.connectedWalletAddress = walletAddress;
4367
- // Create WatchOnlyWallet with the connected address
4368
- this.watchOnlyWallet = new (0, $f4ad400261a08cba$export$2e2bcd8739ae039)([
4369
- {
4370
- address: walletAddress
4371
- }
4372
- ], this.currentNetwork);
4373
- return walletAddress;
4374
- } catch (error) {
4375
- throw new Error(`Failed to connect wallet: ${error instanceof Error ? error.message : 'Unknown error'}`);
4376
- }
4377
- }
4378
- /**
4379
- * Send NEXA to an address
4380
- * @param toAddress Destination address
4381
- * @param amount Amount in satoshis (as string)
4382
- * @param opReturnData Optional OP_RETURN data
4383
- * @param broadcast Whether to broadcast immediately (default true)
4384
- * @returns Promise resolving to transaction ID or signed hex
4385
- */ async sendTransaction(toAddress, amount, opReturnData, broadcast = true) {
4386
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4387
- // Create unsigned transaction using WatchOnlyWallet
4388
- let txBuilder = this.watchOnlyWallet.newTransaction().sendTo(toAddress, amount);
4389
- // Add OP_RETURN data if provided
4390
- if (opReturnData) txBuilder = txBuilder.addOpReturn(opReturnData);
4391
- // Populate and build unsigned transaction
4392
- const unsignedTx = await txBuilder.populate().build();
4393
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4394
- }
4395
- /**
4396
- * Send tokens to an address
4397
- * @param toAddress Destination address
4398
- * @param amount Amount of tokens (as string)
4399
- * @param tokenId Token ID
4400
- * @param opReturnData Optional OP_RETURN data
4401
- * @param broadcast Whether to broadcast immediately (default true)
4402
- * @returns Promise resolving to transaction ID or signed hex
4403
- */ async sendTokenTransaction(toAddress, amount, tokenId, opReturnData, broadcast = true) {
4404
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4405
- // Create unsigned token transaction
4406
- let txBuilder = this.watchOnlyWallet.newTransaction().sendToToken(toAddress, amount, tokenId);
4407
- // Add OP_RETURN data if provided
4408
- if (opReturnData) txBuilder = txBuilder.addOpReturn(opReturnData);
4409
- // Populate and build unsigned transaction
4410
- const unsignedTx = await txBuilder.populate().build();
4411
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4412
- }
4413
- /**
4414
- * Create and mint a new token
4415
- * @param name Token name
4416
- * @param ticker Token ticker symbol
4417
- * @param decimals Number of decimal places
4418
- * @param docUrl URL to token documentation
4419
- * @param docHash Hash of token documentation
4420
- * @param broadcast Whether to broadcast immediately (default true)
4421
- * @returns Promise resolving to transaction ID or signed hex
4422
- */ async createToken(name, ticker, decimals, docUrl, docHash, broadcast = true) {
4423
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4424
- // Create token creation transaction
4425
- const unsignedTx = await this.watchOnlyWallet.newTransaction().token(name, ticker, decimals, docUrl, docHash).populate().build();
4426
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4427
- }
4428
- /**
4429
- * Create and mint a new NFT collection
4430
- * @param name Collection name
4431
- * @param ticker Collection ticker symbol
4432
- * @param docUrl URL to collection documentation
4433
- * @param docHash Hash of collection documentation
4434
- * @param broadcast Whether to broadcast immediately (default true)
4435
- * @returns Promise resolving to transaction ID or signed hex
4436
- */ async createCollection(name, ticker, docUrl, docHash, broadcast = true) {
4437
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4438
- // Create collection creation transaction
4439
- const unsignedTx = await this.watchOnlyWallet.newTransaction().collection(name, ticker, docUrl, docHash).populate().build();
4440
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4441
- }
4442
- /**
4443
- * Create and mint an NFT within a collection
4444
- * @param parentCollection Parent collection token ID
4445
- * @param zipUrl URL to NFT content ZIP file
4446
- * @param zipHash Hash of NFT content ZIP file
4447
- * @param broadcast Whether to broadcast immediately (default true)
4448
- * @returns Promise resolving to transaction ID or signed hex
4449
- */ async createNFT(parentCollection, zipUrl, zipHash, broadcast = true) {
4450
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4451
- // Create NFT creation transaction
4452
- const unsignedTx = await this.watchOnlyWallet.newTransaction().nft(parentCollection, zipUrl, zipHash).populate().build();
4453
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4454
- }
4455
- /**
4456
- * Create and mint an SFT (Semi-Fungible Token) within a collection with specified quantity
4457
- * @param parentCollection Parent collection token ID
4458
- * @param zipUrl URL to SFT content ZIP file
4459
- * @param zipHash Hash of SFT content ZIP file
4460
- * @param quantity Quantity of SFTs to create
4461
- * @param broadcast Whether to broadcast immediately (default true)
4462
- * @returns Promise resolving to transaction ID or signed hex
4463
- */ async createSFT(parentCollection, zipUrl, zipHash, quantity, broadcast = true) {
4464
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4465
- // Create SFT creation transaction
4466
- const unsignedTx = await this.watchOnlyWallet.newTransaction().sft(parentCollection, zipUrl, zipHash, quantity).populate().build();
4467
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4468
- }
4469
- /**
4470
- * Sign an arbitrary unsigned transaction
4471
- * @param unsignedTx Unsigned transaction hex string
4472
- * @param sighashSpec Optional sighash specification for selective signing
4473
- * @param broadcast Whether to broadcast immediately (default false)
4474
- * @returns Promise resolving to transaction ID (if broadcast) or signed hex
4475
- */ async signTransaction(unsignedTx, sighashSpec, broadcast = false) {
4476
- if (!this.connectedWalletAddress) throw new Error('No wallet connected');
4477
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4478
- }
4479
- /**
4480
- * Build an unsigned transaction without signing
4481
- * @param toAddress Destination address
4482
- * @param amount Amount in satoshis (as string)
4483
- * @param tokenId Optional token ID for token transfers
4484
- * @param opReturnData Optional OP_RETURN data
4485
- * @returns Promise resolving to unsigned transaction hex
4486
- */ async buildTransaction(toAddress, amount, tokenId, opReturnData) {
4487
- if (!this.watchOnlyWallet) throw new Error('No wallet connected');
4488
- let txBuilder = this.watchOnlyWallet.newTransaction();
4489
- if (tokenId) txBuilder = txBuilder.sendToToken(toAddress, amount, tokenId);
4490
- else txBuilder = txBuilder.sendTo(toAddress, amount);
4491
- if (opReturnData) txBuilder = txBuilder.addOpReturn(opReturnData);
4492
- return await txBuilder.populate().build();
4493
- }
4494
- /**
4495
- * Build an unsigned token creation transaction
4496
- * @param name Token name
4497
- * @param ticker Token ticker symbol
4498
- * @param decimals Number of decimal places
4499
- * @param docUrl URL to token documentation
4500
- * @param docHash Hash of token documentation
4501
- * @returns Promise resolving to unsigned transaction hex
4502
- */ async buildTokenCreation(name, ticker, decimals, docUrl, docHash) {
4503
- if (!this.watchOnlyWallet) throw new Error('No wallet connected');
4504
- return await this.watchOnlyWallet.newTransaction().token(name, ticker, decimals, docUrl, docHash).populate().build();
4505
- }
4506
- /**
4507
- * Build an unsigned collection creation transaction
4508
- * @param name Collection name
4509
- * @param ticker Collection ticker symbol
4510
- * @param docUrl URL to collection documentation
4511
- * @param docHash Hash of collection documentation
4512
- * @returns Promise resolving to unsigned transaction hex
4513
- */ async buildCollectionCreation(name, ticker, docUrl, docHash) {
4514
- if (!this.watchOnlyWallet) throw new Error('No wallet connected');
4515
- return await this.watchOnlyWallet.newTransaction().collection(name, ticker, docUrl, docHash).populate().build();
4516
- }
4517
- /**
4518
- * Build an unsigned NFT creation transaction
4519
- * @param parentCollection Parent collection token ID
4520
- * @param zipUrl URL to NFT content ZIP file
4521
- * @param zipHash Hash of NFT content ZIP file
4522
- * @returns Promise resolving to unsigned transaction hex
4523
- */ async buildNFTCreation(parentCollection, zipUrl, zipHash) {
4524
- if (!this.watchOnlyWallet) throw new Error('No wallet connected');
4525
- return await this.watchOnlyWallet.newTransaction().nft(parentCollection, zipUrl, zipHash).populate().build();
4526
- }
4527
- /**
4528
- * Build an unsigned SFT creation transaction
4529
- * @param parentCollection Parent collection token ID
4530
- * @param zipUrl URL to SFT content ZIP file
4531
- * @param zipHash Hash of SFT content ZIP file
4532
- * @param quantity Quantity of SFTs to create
4533
- * @returns Promise resolving to unsigned transaction hex
4534
- */ async buildSFTCreation(parentCollection, zipUrl, zipHash, quantity) {
4535
- if (!this.watchOnlyWallet) throw new Error('No wallet connected');
4536
- return await this.watchOnlyWallet.newTransaction().sft(parentCollection, zipUrl, zipHash, quantity).populate().build();
4537
- }
4538
- /**
4539
- * Initialize WatchOnlyWallet with multiple addresses
4540
- * @param addresses Array of addresses to watch
4541
- */ initializeWatchOnly(addresses) {
4542
- this.watchOnlyWallet = new (0, $f4ad400261a08cba$export$2e2bcd8739ae039)(addresses.map((addr)=>({
4543
- address: addr
4544
- })), this.currentNetwork);
4545
- }
4546
- /**
4547
- * Create a custom unsigned transaction
4548
- * @param txBuilder Function that configures the transaction builder
4549
- * @param sighashSpec Optional sighash specification for selective signing
4550
- * @param broadcast Whether to broadcast immediately (default true)
4551
- * @returns Promise resolving to transaction ID or signed hex
4552
- */ async createCustomTransaction(txBuilder, sighashSpec, broadcast = true) {
4553
- if (!this.watchOnlyWallet || !this.connectedWalletAddress) throw new Error('No wallet connected');
4554
- // Create custom transaction using provided builder function
4555
- const builder = this.watchOnlyWallet.newTransaction();
4556
- const configuredBuilder = txBuilder(builder);
4557
- const unsignedTx = await configuredBuilder.populate().build();
4558
- return await this.provider.signTransaction(this.connectedWalletAddress, unsignedTx, broadcast);
4559
- }
4560
- /**
4561
- * Get the connected wallet's current account address
4562
- * @param timeout Timeout in milliseconds (default 30000)
4563
- * @param signal Optional AbortSignal to cancel the request
4564
- * @returns Promise resolving to the account address
4565
- */ async getAccount(timeout = 30000, signal) {
4566
- return await this.provider.getAccount(timeout, signal);
4567
- }
4568
- /**
4569
- * Request the wallet to add a token to its token list
4570
- * @param token Token ID to add
4571
- * @param timeout Timeout in milliseconds (default 30000)
4572
- * @param signal Optional AbortSignal to cancel the request
4573
- * @returns Promise resolving to true if token was added
4574
- */ async addToken(token, timeout = 30000, signal) {
4575
- if (!this.connectedWalletAddress) throw new Error('No wallet connected');
4576
- return await this.provider.addToken(this.connectedWalletAddress, token, timeout, signal);
4577
- }
4578
- /**
4579
- * Sign a message with the connected wallet
4580
- * @param message Message to sign
4581
- * @param timeout Timeout in milliseconds (default 30000)
4582
- * @param signal Optional AbortSignal to cancel the request
4583
- * @returns Promise resolving to the signature
4584
- */ async signMessage(message, timeout = 30000, signal) {
4585
- if (!this.connectedWalletAddress) throw new Error('No wallet connected');
4586
- return await this.provider.signMessage(this.connectedWalletAddress, message, timeout, signal);
4587
- }
4588
- /**
4589
- * Switch to a different network
4590
- * @param network Network name or identifier
4591
- * @param timeout Timeout in milliseconds (default 30000)
4592
- * @param signal Optional AbortSignal to cancel the request
4593
- * @returns Promise resolving to true if network was switched
4594
- */ async switchNetwork(network, timeout = 30000, signal) {
4595
- const result = await this.provider.switchNetwork(network, timeout, signal);
4596
- this.currentNetwork = network;
4597
- // Reconnect rostrum provider to new network
4598
- await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).connect(network);
4599
- // Update watch-only wallet network if connected
4600
- if (this.watchOnlyWallet && this.connectedWalletAddress) this.watchOnlyWallet = new (0, $f4ad400261a08cba$export$2e2bcd8739ae039)([
4601
- {
4602
- address: this.connectedWalletAddress
4603
- }
4604
- ], network);
4605
- return result;
4606
- }
4607
- /**
4608
- * Get the currently connected wallet address
4609
- * @returns Wallet address or null if not connected
4610
- */ getConnectedWallet() {
4611
- return this.connectedWalletAddress;
4612
- }
4613
- /**
4614
- * Check if a wallet is currently connected
4615
- * @returns True if wallet is connected
4616
- */ isConnected() {
4617
- return this.connectedWalletAddress !== null;
4618
- }
4619
- /**
4620
- * Get the current network
4621
- * @returns Current network identifier
4622
- */ getCurrentNetwork() {
4623
- return this.currentNetwork;
4624
- }
4625
- /**
4626
- * Get the underlying WatchOnlyWallet instance
4627
- * @returns WatchOnlyWallet instance or null if not connected
4628
- */ getWatchOnlyWallet() {
4629
- return this.watchOnlyWallet;
4630
- }
4631
- /**
4632
- * Disconnect from the wallet
4633
- */ disconnect() {
4634
- this.provider.disconnect();
4635
- this.watchOnlyWallet = null;
4636
- this.connectedWalletAddress = null;
4637
- }
4638
- /**
4639
- * Set up event listeners for wallet events
4640
- * @param event Event name
4641
- * @param callback Event callback
4642
- */ on(event, callback) {
4643
- this.provider.on(event, callback);
4644
- }
4645
- /**
4646
- * Remove event listeners
4647
- * @param event Event name
4648
- */ off(event) {
4649
- this.provider.off(event);
4650
- }
4651
- /**
4652
- * Set up wallet join event listener
4653
- * @param callback Function to call when a wallet joins the session
4654
- */ onWalletJoin(callback) {
4655
- this.provider.onWalletJoin((address)=>{
4656
- this.connectedWalletAddress = address;
4657
- // Create WatchOnlyWallet with the connected address
4658
- this.watchOnlyWallet = new (0, $f4ad400261a08cba$export$2e2bcd8739ae039)([
4659
- {
4660
- address: address
4661
- }
4662
- ], this.currentNetwork);
4663
- callback(address);
4664
- });
4665
- }
4666
- /**
4667
- * Set up wallet disconnect event listener
4668
- * @param callback Function to call when wallet disconnects
4669
- */ onWalletDisconnect(callback) {
4670
- this.provider.onPeerDisconnect(()=>{
4671
- this.watchOnlyWallet = null;
4672
- this.connectedWalletAddress = null;
4673
- callback();
4674
- });
4675
- }
4676
- /**
4677
- * Set up connection close event listener
4678
- * @param callback Function to call when connection closes
4679
- */ onConnectionClose(callback) {
4680
- this.provider.onClose(()=>{
4681
- this.watchOnlyWallet = null;
4682
- this.connectedWalletAddress = null;
4683
- callback();
4684
- });
4685
- }
4686
- /**
4687
- * Get session information
4688
- * @returns Session details including sessionId, secret, relayUrl
4689
- */ getSessionInfo() {
4690
- return this.provider.getSessionInfo();
4691
- }
4692
- }
4693
- var $4d217697e55d958e$export$2e2bcd8739ae039 = $4d217697e55d958e$export$80793d8292a1630a;
4694
-
4695
-
4696
-
4697
-
4698
-
4699
3990
  /**
4700
3991
  * Guards against multiple instances of the wallet SDK being loaded.
4701
3992
  * This prevents conflicts and ensures only one version is active at a time.