nexa-wallet-sdk 0.6.0 → 0.6.2
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 +35 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +35 -37
- package/dist/index.mjs.map +1 -1
- package/dist/index.web.mjs +35 -37
- package/dist/index.web.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -149,7 +149,7 @@ $parcel$export(module.exports, "SighashType", () => $l50U0$libnexats.SighashType
|
|
|
149
149
|
$parcel$export(module.exports, "AccountKeysUtils", () => $4d68f29c39c1a3e4$export$94f569bf4eb0f6f6);
|
|
150
150
|
// @ts-ignore
|
|
151
151
|
var $2dd241e44b9dc3c2$exports = {};
|
|
152
|
-
$2dd241e44b9dc3c2$exports = JSON.parse("{\"name\":\"nexa-wallet-sdk\",\"version\":\"0.6.
|
|
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}}");
|
|
153
153
|
|
|
154
154
|
|
|
155
155
|
|
|
@@ -4064,8 +4064,10 @@ class $23698d921173fdf9$export$11e896a2f3ae4119 {
|
|
|
4064
4064
|
this.provider = new (0, $l50U0$walletcommssdk.DAppProvider)(pairingURI);
|
|
4065
4065
|
// Set up request handlers
|
|
4066
4066
|
this.setupHandlers();
|
|
4067
|
-
// Connect to the
|
|
4068
|
-
|
|
4067
|
+
// Connect to the relay server
|
|
4068
|
+
await this.provider.connect();
|
|
4069
|
+
// Get dApp information
|
|
4070
|
+
const dAppInfo = await this.provider.getAppInfo();
|
|
4069
4071
|
// Request approval for connection if callback is provided
|
|
4070
4072
|
if (this.approvalCallbacks.approveConnection) {
|
|
4071
4073
|
const approved = await this.approvalCallbacks.approveConnection(dAppInfo);
|
|
@@ -4135,24 +4137,13 @@ class $23698d921173fdf9$export$11e896a2f3ae4119 {
|
|
|
4135
4137
|
}
|
|
4136
4138
|
});
|
|
4137
4139
|
// Handle get account requests
|
|
4138
|
-
this.provider.
|
|
4140
|
+
this.provider.onGetAccount(async ()=>{
|
|
4139
4141
|
if (!this.currentAccount) throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InternalError, 'No account selected');
|
|
4140
4142
|
const primaryAddress = this.currentAccount.getPrimaryAddressKey();
|
|
4141
4143
|
return primaryAddress.address;
|
|
4142
4144
|
});
|
|
4143
|
-
// Handle get accounts (multiple) requests - only return DApp accounts
|
|
4144
|
-
this.provider.on('wallet_getAccounts', async ()=>{
|
|
4145
|
-
const dappAccounts = this.wallet.accountStore.getAccountsByType((0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).DAPP_ACCOUNT);
|
|
4146
|
-
const addresses = [];
|
|
4147
|
-
// Return addresses from all DApp accounts
|
|
4148
|
-
for (const account of dappAccounts){
|
|
4149
|
-
const primaryAddress = account.getPrimaryAddressKey();
|
|
4150
|
-
addresses.push(primaryAddress.address);
|
|
4151
|
-
}
|
|
4152
|
-
return addresses;
|
|
4153
|
-
});
|
|
4154
4145
|
// Handle transaction signing requests
|
|
4155
|
-
this.provider.
|
|
4146
|
+
this.provider.onSignTransaction(async (request)=>{
|
|
4156
4147
|
try {
|
|
4157
4148
|
const account = this.getAccountByAddress(request.account);
|
|
4158
4149
|
if (!account) throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InvalidParams, `Account ${request.account} not found`);
|
|
@@ -4201,19 +4192,20 @@ class $23698d921173fdf9$export$11e896a2f3ae4119 {
|
|
|
4201
4192
|
}
|
|
4202
4193
|
});
|
|
4203
4194
|
// Handle send transaction requests
|
|
4204
|
-
this.provider.
|
|
4195
|
+
this.provider.onSendTransaction(async (request)=>{
|
|
4205
4196
|
try {
|
|
4206
4197
|
const account = this.getAccountByAddress(request.from);
|
|
4207
4198
|
if (!account) throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InvalidParams, `Account ${request.from} not found`);
|
|
4208
|
-
// Calculate total amount
|
|
4209
|
-
|
|
4210
|
-
for (const recipient of request.to)if (!recipient.token) totalAmount += BigInt(recipient.amount);
|
|
4199
|
+
// Calculate total amount (request.to is now a single recipient object)
|
|
4200
|
+
const totalAmount = !request.to.token ? BigInt(request.to.amount) : BigInt(0);
|
|
4211
4201
|
// Request approval for sending transaction
|
|
4212
4202
|
if (this.approvalCallbacks.approveSendTransaction && this.connectedDApp) {
|
|
4213
4203
|
const approvalDetails = {
|
|
4214
4204
|
dApp: this.connectedDApp,
|
|
4215
4205
|
fromAccount: request.from,
|
|
4216
|
-
recipients:
|
|
4206
|
+
recipients: [
|
|
4207
|
+
request.to
|
|
4208
|
+
],
|
|
4217
4209
|
totalAmount: totalAmount.toString(),
|
|
4218
4210
|
opReturn: request.data
|
|
4219
4211
|
};
|
|
@@ -4221,52 +4213,51 @@ class $23698d921173fdf9$export$11e896a2f3ae4119 {
|
|
|
4221
4213
|
if (!approved) throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).RequestRejected, 'Send transaction rejected by user');
|
|
4222
4214
|
}
|
|
4223
4215
|
let txBuilder = this.wallet.newTransaction(account).onNetwork(this.wallet.network);
|
|
4224
|
-
// Add
|
|
4225
|
-
|
|
4226
|
-
else txBuilder = txBuilder.sendTo(
|
|
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);
|
|
4227
4219
|
// Add OP_RETURN data if provided
|
|
4228
4220
|
if (request.data) txBuilder = txBuilder.addOpReturn(request.data);
|
|
4229
4221
|
// Build and send the transaction
|
|
4230
4222
|
const tx = await txBuilder.populate().sign().build();
|
|
4231
4223
|
const txId = await this.wallet.sendTransaction(tx);
|
|
4232
|
-
return
|
|
4233
|
-
txId: txId,
|
|
4234
|
-
hex: tx
|
|
4235
|
-
};
|
|
4224
|
+
return txId; // Return just the txId string
|
|
4236
4225
|
} catch (error) {
|
|
4237
4226
|
throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InternalError, error instanceof Error ? error.message : 'Failed to send transaction');
|
|
4238
4227
|
}
|
|
4239
4228
|
});
|
|
4240
4229
|
// Handle network switching requests
|
|
4241
|
-
this.provider.
|
|
4230
|
+
this.provider.onSwitchNetwork(async (request)=>{
|
|
4242
4231
|
try {
|
|
4243
4232
|
// Validate network
|
|
4244
4233
|
const network = (0, $l50U0$libnexats.Networks).get(request.network);
|
|
4245
4234
|
if (!network) throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InvalidParams, `Unknown network: ${request.network}`);
|
|
4246
4235
|
// Reconnect to the new network
|
|
4247
4236
|
await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).connect(request.network);
|
|
4248
|
-
return
|
|
4249
|
-
success: true,
|
|
4250
|
-
network: request.network
|
|
4251
|
-
};
|
|
4237
|
+
return true;
|
|
4252
4238
|
} catch (error) {
|
|
4253
4239
|
throw new (0, $l50U0$walletcommssdk.JsonRpcError)((0, $l50U0$walletcommssdk.JsonRpcErrorCode).InternalError, error instanceof Error ? error.message : 'Failed to switch network');
|
|
4254
4240
|
}
|
|
4255
4241
|
});
|
|
4256
4242
|
// Handle add token requests
|
|
4257
|
-
this.provider.
|
|
4243
|
+
this.provider.onAddToken(async (request)=>{
|
|
4258
4244
|
// This would need implementation based on how tokens are tracked
|
|
4259
4245
|
// For now, we'll acknowledge but not implement
|
|
4260
4246
|
console.log('Add token request:', request);
|
|
4261
|
-
return
|
|
4262
|
-
success: true
|
|
4263
|
-
};
|
|
4247
|
+
return true;
|
|
4264
4248
|
});
|
|
4265
4249
|
// Handle peer disconnect
|
|
4266
4250
|
this.provider.onPeerDisconnect(()=>{
|
|
4267
4251
|
console.log('DApp disconnected');
|
|
4268
4252
|
this.isConnected = false;
|
|
4269
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
|
+
});
|
|
4270
4261
|
// Handle connection close
|
|
4271
4262
|
this.provider.onClose(()=>{
|
|
4272
4263
|
console.log('Connection closed');
|
|
@@ -4304,6 +4295,13 @@ class $23698d921173fdf9$export$11e896a2f3ae4119 {
|
|
|
4304
4295
|
if (!this.provider) return null;
|
|
4305
4296
|
return this.provider.getSessionInfo();
|
|
4306
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
|
+
}
|
|
4307
4305
|
}
|
|
4308
4306
|
|
|
4309
4307
|
|