@solana-mobile/mobile-wallet-adapter-protocol-web3js 0.0.1-alpha.7 → 0.0.1-alpha.8

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.
@@ -4,6 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var web3_js = require('@solana/web3.js');
6
6
  var mobileWalletAdapterProtocol = require('@solana-mobile/mobile-wallet-adapter-protocol');
7
+ var bs58 = require('bs58');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
7
12
 
8
13
  /******************************************************************************
9
14
  Copyright (c) Microsoft Corporation.
@@ -20,6 +25,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
25
  PERFORMANCE OF THIS SOFTWARE.
21
26
  ***************************************************************************** */
22
27
 
28
+ function __rest(s, e) {
29
+ var t = {};
30
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
31
+ t[p] = s[p];
32
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
33
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
34
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
35
+ t[p[i]] = s[p[i]];
36
+ }
37
+ return t;
38
+ }
39
+
23
40
  function __awaiter(thisArg, _arguments, P, generator) {
24
41
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
25
42
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -47,26 +64,35 @@ function transact(callback, config) {
47
64
  get(target, p) {
48
65
  if (target[p] == null) {
49
66
  switch (p) {
50
- case 'signAndSendTransaction':
51
- target[p] = function (params) {
67
+ case 'signAndSendTransactions':
68
+ target[p] = function (_a) {
69
+ var { connection, fee_payer: feePayer, transactions } = _a, rest = __rest(_a, ["connection", "fee_payer", "transactions"]);
52
70
  return __awaiter(this, void 0, void 0, function* () {
53
71
  let latestBlockhashPromise;
54
- function getLatestBlockhash(connection) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- if (latestBlockhashPromise == null) {
57
- latestBlockhashPromise = connection.getLatestBlockhash({
58
- commitment: connection.commitment,
59
- });
60
- }
61
- return yield latestBlockhashPromise;
62
- });
72
+ let targetCommitment;
73
+ switch (connection.commitment) {
74
+ case 'confirmed':
75
+ case 'finalized':
76
+ case 'processed':
77
+ targetCommitment = connection.commitment;
78
+ break;
79
+ default:
80
+ targetCommitment = 'finalized';
63
81
  }
64
- const payloads = yield Promise.all(params.transactions.map((transaction) => __awaiter(this, void 0, void 0, function* () {
82
+ function getLatestBlockhashPromise() {
83
+ if (latestBlockhashPromise == null) {
84
+ latestBlockhashPromise = connection.getLatestBlockhash({
85
+ commitment: targetCommitment,
86
+ });
87
+ }
88
+ return latestBlockhashPromise;
89
+ }
90
+ const payloads = yield Promise.all(transactions.map((transaction) => __awaiter(this, void 0, void 0, function* () {
65
91
  if (transaction.feePayer == null) {
66
- transaction.feePayer = params.fee_payer;
92
+ transaction.feePayer = feePayer;
67
93
  }
68
94
  if (transaction.recentBlockhash == null) {
69
- const { blockhash } = yield getLatestBlockhash(params.connection);
95
+ const { blockhash } = yield getLatestBlockhashPromise();
70
96
  transaction.recentBlockhash = blockhash;
71
97
  }
72
98
  const serializedTransaction = transaction.serialize({
@@ -75,53 +101,36 @@ function transact(callback, config) {
75
101
  });
76
102
  return serializedTransaction.toString('base64');
77
103
  })));
78
- let targetCommitment;
79
- switch (params.connection.commitment) {
80
- case 'confirmed':
81
- case 'finalized':
82
- case 'processed':
83
- targetCommitment = params.connection.commitment;
84
- break;
85
- default:
86
- targetCommitment = 'finalized';
87
- }
88
- const { signatures } = yield wallet.signAndSendTransaction({
89
- auth_token: params.auth_token,
90
- commitment: targetCommitment,
91
- payloads,
92
- });
104
+ const { signatures: base64EncodedSignatures } = yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, rest), { commitment: targetCommitment, payloads, preflight_commitment: targetCommitment }));
105
+ const signatures = base64EncodedSignatures.map(toUint8Array).map(bs58__default["default"].encode);
93
106
  return signatures;
94
107
  });
95
108
  };
96
109
  break;
97
- case 'signMessage':
98
- target[p] = function (params) {
110
+ case 'signMessages':
111
+ target[p] = function (_a) {
112
+ var { payloads } = _a, rest = __rest(_a, ["payloads"]);
99
113
  return __awaiter(this, void 0, void 0, function* () {
100
- const payloads = params.payloads.map(fromUint8Array);
101
- const { signed_payloads: base64EncodedSignedMessages } = yield wallet.signMessage({
102
- auth_token: params.auth_token,
103
- payloads,
104
- });
114
+ const base64EncodedPayloads = payloads.map(fromUint8Array);
115
+ const { signed_payloads: base64EncodedSignedMessages } = yield wallet.signMessages(Object.assign(Object.assign({}, rest), { payloads: base64EncodedPayloads }));
105
116
  const signedMessages = base64EncodedSignedMessages.map(toUint8Array);
106
117
  return signedMessages;
107
118
  });
108
119
  };
109
120
  break;
110
- case 'signTransaction':
111
- target[p] = function (params) {
121
+ case 'signTransactions':
122
+ target[p] = function (_a) {
123
+ var { transactions } = _a, rest = __rest(_a, ["transactions"]);
112
124
  return __awaiter(this, void 0, void 0, function* () {
113
- const serializedTransactions = params.transactions.map((transaction) => transaction.serialize({
125
+ const serializedTransactions = transactions.map((transaction) => transaction.serialize({
114
126
  requireAllSignatures: false,
115
127
  verifySignatures: false,
116
128
  }));
117
129
  const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
118
- const { signed_payloads: base64EncodedCompiledTransactions } = yield wallet.signTransaction({
119
- auth_token: params.auth_token,
120
- payloads,
121
- });
130
+ const { signed_payloads: base64EncodedCompiledTransactions } = yield wallet.signTransactions(Object.assign(Object.assign({}, rest), { payloads }));
122
131
  const compiledTransactions = base64EncodedCompiledTransactions.map(toUint8Array);
123
- const transactions = compiledTransactions.map(web3_js.Transaction.from);
124
- return transactions;
132
+ const signedTransactions = compiledTransactions.map(web3_js.Transaction.from);
133
+ return signedTransactions;
125
134
  });
126
135
  };
127
136
  break;
package/lib/cjs/index.js CHANGED
@@ -4,6 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var web3_js = require('@solana/web3.js');
6
6
  var mobileWalletAdapterProtocol = require('@solana-mobile/mobile-wallet-adapter-protocol');
7
+ var bs58 = require('bs58');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
7
12
 
8
13
  /******************************************************************************
9
14
  Copyright (c) Microsoft Corporation.
@@ -20,6 +25,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
25
  PERFORMANCE OF THIS SOFTWARE.
21
26
  ***************************************************************************** */
22
27
 
28
+ function __rest(s, e) {
29
+ var t = {};
30
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
31
+ t[p] = s[p];
32
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
33
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
34
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
35
+ t[p[i]] = s[p[i]];
36
+ }
37
+ return t;
38
+ }
39
+
23
40
  function __awaiter(thisArg, _arguments, P, generator) {
24
41
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
25
42
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -47,26 +64,35 @@ function transact(callback, config) {
47
64
  get(target, p) {
48
65
  if (target[p] == null) {
49
66
  switch (p) {
50
- case 'signAndSendTransaction':
51
- target[p] = function (params) {
67
+ case 'signAndSendTransactions':
68
+ target[p] = function (_a) {
69
+ var { connection, fee_payer: feePayer, transactions } = _a, rest = __rest(_a, ["connection", "fee_payer", "transactions"]);
52
70
  return __awaiter(this, void 0, void 0, function* () {
53
71
  let latestBlockhashPromise;
54
- function getLatestBlockhash(connection) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- if (latestBlockhashPromise == null) {
57
- latestBlockhashPromise = connection.getLatestBlockhash({
58
- commitment: connection.commitment,
59
- });
60
- }
61
- return yield latestBlockhashPromise;
62
- });
72
+ let targetCommitment;
73
+ switch (connection.commitment) {
74
+ case 'confirmed':
75
+ case 'finalized':
76
+ case 'processed':
77
+ targetCommitment = connection.commitment;
78
+ break;
79
+ default:
80
+ targetCommitment = 'finalized';
63
81
  }
64
- const payloads = yield Promise.all(params.transactions.map((transaction) => __awaiter(this, void 0, void 0, function* () {
82
+ function getLatestBlockhashPromise() {
83
+ if (latestBlockhashPromise == null) {
84
+ latestBlockhashPromise = connection.getLatestBlockhash({
85
+ commitment: targetCommitment,
86
+ });
87
+ }
88
+ return latestBlockhashPromise;
89
+ }
90
+ const payloads = yield Promise.all(transactions.map((transaction) => __awaiter(this, void 0, void 0, function* () {
65
91
  if (transaction.feePayer == null) {
66
- transaction.feePayer = params.fee_payer;
92
+ transaction.feePayer = feePayer;
67
93
  }
68
94
  if (transaction.recentBlockhash == null) {
69
- const { blockhash } = yield getLatestBlockhash(params.connection);
95
+ const { blockhash } = yield getLatestBlockhashPromise();
70
96
  transaction.recentBlockhash = blockhash;
71
97
  }
72
98
  const serializedTransaction = transaction.serialize({
@@ -75,53 +101,36 @@ function transact(callback, config) {
75
101
  });
76
102
  return serializedTransaction.toString('base64');
77
103
  })));
78
- let targetCommitment;
79
- switch (params.connection.commitment) {
80
- case 'confirmed':
81
- case 'finalized':
82
- case 'processed':
83
- targetCommitment = params.connection.commitment;
84
- break;
85
- default:
86
- targetCommitment = 'finalized';
87
- }
88
- const { signatures } = yield wallet.signAndSendTransaction({
89
- auth_token: params.auth_token,
90
- commitment: targetCommitment,
91
- payloads,
92
- });
104
+ const { signatures: base64EncodedSignatures } = yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, rest), { commitment: targetCommitment, payloads, preflight_commitment: targetCommitment }));
105
+ const signatures = base64EncodedSignatures.map(toUint8Array).map(bs58__default["default"].encode);
93
106
  return signatures;
94
107
  });
95
108
  };
96
109
  break;
97
- case 'signMessage':
98
- target[p] = function (params) {
110
+ case 'signMessages':
111
+ target[p] = function (_a) {
112
+ var { payloads } = _a, rest = __rest(_a, ["payloads"]);
99
113
  return __awaiter(this, void 0, void 0, function* () {
100
- const payloads = params.payloads.map(fromUint8Array);
101
- const { signed_payloads: base64EncodedSignedMessages } = yield wallet.signMessage({
102
- auth_token: params.auth_token,
103
- payloads,
104
- });
114
+ const base64EncodedPayloads = payloads.map(fromUint8Array);
115
+ const { signed_payloads: base64EncodedSignedMessages } = yield wallet.signMessages(Object.assign(Object.assign({}, rest), { payloads: base64EncodedPayloads }));
105
116
  const signedMessages = base64EncodedSignedMessages.map(toUint8Array);
106
117
  return signedMessages;
107
118
  });
108
119
  };
109
120
  break;
110
- case 'signTransaction':
111
- target[p] = function (params) {
121
+ case 'signTransactions':
122
+ target[p] = function (_a) {
123
+ var { transactions } = _a, rest = __rest(_a, ["transactions"]);
112
124
  return __awaiter(this, void 0, void 0, function* () {
113
- const serializedTransactions = params.transactions.map((transaction) => transaction.serialize({
125
+ const serializedTransactions = transactions.map((transaction) => transaction.serialize({
114
126
  requireAllSignatures: false,
115
127
  verifySignatures: false,
116
128
  }));
117
129
  const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
118
- const { signed_payloads: base64EncodedCompiledTransactions } = yield wallet.signTransaction({
119
- auth_token: params.auth_token,
120
- payloads,
121
- });
130
+ const { signed_payloads: base64EncodedCompiledTransactions } = yield wallet.signTransactions(Object.assign(Object.assign({}, rest), { payloads }));
122
131
  const compiledTransactions = base64EncodedCompiledTransactions.map(toUint8Array);
123
- const transactions = compiledTransactions.map(web3_js.Transaction.from);
124
- return transactions;
132
+ const signedTransactions = compiledTransactions.map(web3_js.Transaction.from);
133
+ return signedTransactions;
125
134
  });
126
135
  };
127
136
  break;
@@ -4,8 +4,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var web3_js = require('@solana/web3.js');
6
6
  var mobileWalletAdapterProtocol = require('@solana-mobile/mobile-wallet-adapter-protocol');
7
+ var bs58 = require('bs58');
7
8
  var jsBase64 = require('js-base64');
8
9
 
10
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
+
12
+ var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
13
+
9
14
  /******************************************************************************
10
15
  Copyright (c) Microsoft Corporation.
11
16
 
@@ -21,6 +26,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
26
  PERFORMANCE OF THIS SOFTWARE.
22
27
  ***************************************************************************** */
23
28
 
29
+ function __rest(s, e) {
30
+ var t = {};
31
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
32
+ t[p] = s[p];
33
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
34
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
35
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
36
+ t[p[i]] = s[p[i]];
37
+ }
38
+ return t;
39
+ }
40
+
24
41
  function __awaiter(thisArg, _arguments, P, generator) {
25
42
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
43
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -38,26 +55,35 @@ function transact(callback, config) {
38
55
  get(target, p) {
39
56
  if (target[p] == null) {
40
57
  switch (p) {
41
- case 'signAndSendTransaction':
42
- target[p] = function (params) {
58
+ case 'signAndSendTransactions':
59
+ target[p] = function (_a) {
60
+ var { connection, fee_payer: feePayer, transactions } = _a, rest = __rest(_a, ["connection", "fee_payer", "transactions"]);
43
61
  return __awaiter(this, void 0, void 0, function* () {
44
62
  let latestBlockhashPromise;
45
- function getLatestBlockhash(connection) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- if (latestBlockhashPromise == null) {
48
- latestBlockhashPromise = connection.getLatestBlockhash({
49
- commitment: connection.commitment,
50
- });
51
- }
52
- return yield latestBlockhashPromise;
53
- });
63
+ let targetCommitment;
64
+ switch (connection.commitment) {
65
+ case 'confirmed':
66
+ case 'finalized':
67
+ case 'processed':
68
+ targetCommitment = connection.commitment;
69
+ break;
70
+ default:
71
+ targetCommitment = 'finalized';
54
72
  }
55
- const payloads = yield Promise.all(params.transactions.map((transaction) => __awaiter(this, void 0, void 0, function* () {
73
+ function getLatestBlockhashPromise() {
74
+ if (latestBlockhashPromise == null) {
75
+ latestBlockhashPromise = connection.getLatestBlockhash({
76
+ commitment: targetCommitment,
77
+ });
78
+ }
79
+ return latestBlockhashPromise;
80
+ }
81
+ const payloads = yield Promise.all(transactions.map((transaction) => __awaiter(this, void 0, void 0, function* () {
56
82
  if (transaction.feePayer == null) {
57
- transaction.feePayer = params.fee_payer;
83
+ transaction.feePayer = feePayer;
58
84
  }
59
85
  if (transaction.recentBlockhash == null) {
60
- const { blockhash } = yield getLatestBlockhash(params.connection);
86
+ const { blockhash } = yield getLatestBlockhashPromise();
61
87
  transaction.recentBlockhash = blockhash;
62
88
  }
63
89
  const serializedTransaction = transaction.serialize({
@@ -66,53 +92,36 @@ function transact(callback, config) {
66
92
  });
67
93
  return serializedTransaction.toString('base64');
68
94
  })));
69
- let targetCommitment;
70
- switch (params.connection.commitment) {
71
- case 'confirmed':
72
- case 'finalized':
73
- case 'processed':
74
- targetCommitment = params.connection.commitment;
75
- break;
76
- default:
77
- targetCommitment = 'finalized';
78
- }
79
- const { signatures } = yield wallet.signAndSendTransaction({
80
- auth_token: params.auth_token,
81
- commitment: targetCommitment,
82
- payloads,
83
- });
95
+ const { signatures: base64EncodedSignatures } = yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, rest), { commitment: targetCommitment, payloads, preflight_commitment: targetCommitment }));
96
+ const signatures = base64EncodedSignatures.map(jsBase64.toUint8Array).map(bs58__default["default"].encode);
84
97
  return signatures;
85
98
  });
86
99
  };
87
100
  break;
88
- case 'signMessage':
89
- target[p] = function (params) {
101
+ case 'signMessages':
102
+ target[p] = function (_a) {
103
+ var { payloads } = _a, rest = __rest(_a, ["payloads"]);
90
104
  return __awaiter(this, void 0, void 0, function* () {
91
- const payloads = params.payloads.map(jsBase64.fromUint8Array);
92
- const { signed_payloads: base64EncodedSignedMessages } = yield wallet.signMessage({
93
- auth_token: params.auth_token,
94
- payloads,
95
- });
105
+ const base64EncodedPayloads = payloads.map(jsBase64.fromUint8Array);
106
+ const { signed_payloads: base64EncodedSignedMessages } = yield wallet.signMessages(Object.assign(Object.assign({}, rest), { payloads: base64EncodedPayloads }));
96
107
  const signedMessages = base64EncodedSignedMessages.map(jsBase64.toUint8Array);
97
108
  return signedMessages;
98
109
  });
99
110
  };
100
111
  break;
101
- case 'signTransaction':
102
- target[p] = function (params) {
112
+ case 'signTransactions':
113
+ target[p] = function (_a) {
114
+ var { transactions } = _a, rest = __rest(_a, ["transactions"]);
103
115
  return __awaiter(this, void 0, void 0, function* () {
104
- const serializedTransactions = params.transactions.map((transaction) => transaction.serialize({
116
+ const serializedTransactions = transactions.map((transaction) => transaction.serialize({
105
117
  requireAllSignatures: false,
106
118
  verifySignatures: false,
107
119
  }));
108
120
  const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
109
- const { signed_payloads: base64EncodedCompiledTransactions } = yield wallet.signTransaction({
110
- auth_token: params.auth_token,
111
- payloads,
112
- });
121
+ const { signed_payloads: base64EncodedCompiledTransactions } = yield wallet.signTransactions(Object.assign(Object.assign({}, rest), { payloads }));
113
122
  const compiledTransactions = base64EncodedCompiledTransactions.map(jsBase64.toUint8Array);
114
- const transactions = compiledTransactions.map(web3_js.Transaction.from);
115
- return transactions;
123
+ const signedTransactions = compiledTransactions.map(web3_js.Transaction.from);
124
+ return signedTransactions;
116
125
  });
117
126
  };
118
127
  break;
@@ -1,5 +1,6 @@
1
1
  import { Transaction } from '@solana/web3.js';
2
2
  import { transact as transact$1 } from '@solana-mobile/mobile-wallet-adapter-protocol';
3
+ import bs58 from 'bs58';
3
4
 
4
5
  /******************************************************************************
5
6
  Copyright (c) Microsoft Corporation.
@@ -16,6 +17,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
17
  PERFORMANCE OF THIS SOFTWARE.
17
18
  ***************************************************************************** */
18
19
 
20
+ function __rest(s, e) {
21
+ var t = {};
22
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
23
+ t[p] = s[p];
24
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
25
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
26
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
27
+ t[p[i]] = s[p[i]];
28
+ }
29
+ return t;
30
+ }
31
+
19
32
  function __awaiter(thisArg, _arguments, P, generator) {
20
33
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21
34
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -43,26 +56,35 @@ function transact(callback, config) {
43
56
  get(target, p) {
44
57
  if (target[p] == null) {
45
58
  switch (p) {
46
- case 'signAndSendTransaction':
47
- target[p] = function (params) {
59
+ case 'signAndSendTransactions':
60
+ target[p] = function (_a) {
61
+ var { connection, fee_payer: feePayer, transactions } = _a, rest = __rest(_a, ["connection", "fee_payer", "transactions"]);
48
62
  return __awaiter(this, void 0, void 0, function* () {
49
63
  let latestBlockhashPromise;
50
- function getLatestBlockhash(connection) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- if (latestBlockhashPromise == null) {
53
- latestBlockhashPromise = connection.getLatestBlockhash({
54
- commitment: connection.commitment,
55
- });
56
- }
57
- return yield latestBlockhashPromise;
58
- });
64
+ let targetCommitment;
65
+ switch (connection.commitment) {
66
+ case 'confirmed':
67
+ case 'finalized':
68
+ case 'processed':
69
+ targetCommitment = connection.commitment;
70
+ break;
71
+ default:
72
+ targetCommitment = 'finalized';
59
73
  }
60
- const payloads = yield Promise.all(params.transactions.map((transaction) => __awaiter(this, void 0, void 0, function* () {
74
+ function getLatestBlockhashPromise() {
75
+ if (latestBlockhashPromise == null) {
76
+ latestBlockhashPromise = connection.getLatestBlockhash({
77
+ commitment: targetCommitment,
78
+ });
79
+ }
80
+ return latestBlockhashPromise;
81
+ }
82
+ const payloads = yield Promise.all(transactions.map((transaction) => __awaiter(this, void 0, void 0, function* () {
61
83
  if (transaction.feePayer == null) {
62
- transaction.feePayer = params.fee_payer;
84
+ transaction.feePayer = feePayer;
63
85
  }
64
86
  if (transaction.recentBlockhash == null) {
65
- const { blockhash } = yield getLatestBlockhash(params.connection);
87
+ const { blockhash } = yield getLatestBlockhashPromise();
66
88
  transaction.recentBlockhash = blockhash;
67
89
  }
68
90
  const serializedTransaction = transaction.serialize({
@@ -71,53 +93,36 @@ function transact(callback, config) {
71
93
  });
72
94
  return serializedTransaction.toString('base64');
73
95
  })));
74
- let targetCommitment;
75
- switch (params.connection.commitment) {
76
- case 'confirmed':
77
- case 'finalized':
78
- case 'processed':
79
- targetCommitment = params.connection.commitment;
80
- break;
81
- default:
82
- targetCommitment = 'finalized';
83
- }
84
- const { signatures } = yield wallet.signAndSendTransaction({
85
- auth_token: params.auth_token,
86
- commitment: targetCommitment,
87
- payloads,
88
- });
96
+ const { signatures: base64EncodedSignatures } = yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, rest), { commitment: targetCommitment, payloads, preflight_commitment: targetCommitment }));
97
+ const signatures = base64EncodedSignatures.map(toUint8Array).map(bs58.encode);
89
98
  return signatures;
90
99
  });
91
100
  };
92
101
  break;
93
- case 'signMessage':
94
- target[p] = function (params) {
102
+ case 'signMessages':
103
+ target[p] = function (_a) {
104
+ var { payloads } = _a, rest = __rest(_a, ["payloads"]);
95
105
  return __awaiter(this, void 0, void 0, function* () {
96
- const payloads = params.payloads.map(fromUint8Array);
97
- const { signed_payloads: base64EncodedSignedMessages } = yield wallet.signMessage({
98
- auth_token: params.auth_token,
99
- payloads,
100
- });
106
+ const base64EncodedPayloads = payloads.map(fromUint8Array);
107
+ const { signed_payloads: base64EncodedSignedMessages } = yield wallet.signMessages(Object.assign(Object.assign({}, rest), { payloads: base64EncodedPayloads }));
101
108
  const signedMessages = base64EncodedSignedMessages.map(toUint8Array);
102
109
  return signedMessages;
103
110
  });
104
111
  };
105
112
  break;
106
- case 'signTransaction':
107
- target[p] = function (params) {
113
+ case 'signTransactions':
114
+ target[p] = function (_a) {
115
+ var { transactions } = _a, rest = __rest(_a, ["transactions"]);
108
116
  return __awaiter(this, void 0, void 0, function* () {
109
- const serializedTransactions = params.transactions.map((transaction) => transaction.serialize({
117
+ const serializedTransactions = transactions.map((transaction) => transaction.serialize({
110
118
  requireAllSignatures: false,
111
119
  verifySignatures: false,
112
120
  }));
113
121
  const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
114
- const { signed_payloads: base64EncodedCompiledTransactions } = yield wallet.signTransaction({
115
- auth_token: params.auth_token,
116
- payloads,
117
- });
122
+ const { signed_payloads: base64EncodedCompiledTransactions } = yield wallet.signTransactions(Object.assign(Object.assign({}, rest), { payloads }));
118
123
  const compiledTransactions = base64EncodedCompiledTransactions.map(toUint8Array);
119
- const transactions = compiledTransactions.map(Transaction.from);
120
- return transactions;
124
+ const signedTransactions = compiledTransactions.map(Transaction.from);
125
+ return signedTransactions;
121
126
  });
122
127
  };
123
128
  break;
package/lib/esm/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Transaction } from '@solana/web3.js';
2
2
  import { transact as transact$1 } from '@solana-mobile/mobile-wallet-adapter-protocol';
3
+ import bs58 from 'bs58';
3
4
 
4
5
  /******************************************************************************
5
6
  Copyright (c) Microsoft Corporation.
@@ -16,6 +17,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
17
  PERFORMANCE OF THIS SOFTWARE.
17
18
  ***************************************************************************** */
18
19
 
20
+ function __rest(s, e) {
21
+ var t = {};
22
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
23
+ t[p] = s[p];
24
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
25
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
26
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
27
+ t[p[i]] = s[p[i]];
28
+ }
29
+ return t;
30
+ }
31
+
19
32
  function __awaiter(thisArg, _arguments, P, generator) {
20
33
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21
34
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -43,26 +56,35 @@ function transact(callback, config) {
43
56
  get(target, p) {
44
57
  if (target[p] == null) {
45
58
  switch (p) {
46
- case 'signAndSendTransaction':
47
- target[p] = function (params) {
59
+ case 'signAndSendTransactions':
60
+ target[p] = function (_a) {
61
+ var { connection, fee_payer: feePayer, transactions } = _a, rest = __rest(_a, ["connection", "fee_payer", "transactions"]);
48
62
  return __awaiter(this, void 0, void 0, function* () {
49
63
  let latestBlockhashPromise;
50
- function getLatestBlockhash(connection) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- if (latestBlockhashPromise == null) {
53
- latestBlockhashPromise = connection.getLatestBlockhash({
54
- commitment: connection.commitment,
55
- });
56
- }
57
- return yield latestBlockhashPromise;
58
- });
64
+ let targetCommitment;
65
+ switch (connection.commitment) {
66
+ case 'confirmed':
67
+ case 'finalized':
68
+ case 'processed':
69
+ targetCommitment = connection.commitment;
70
+ break;
71
+ default:
72
+ targetCommitment = 'finalized';
59
73
  }
60
- const payloads = yield Promise.all(params.transactions.map((transaction) => __awaiter(this, void 0, void 0, function* () {
74
+ function getLatestBlockhashPromise() {
75
+ if (latestBlockhashPromise == null) {
76
+ latestBlockhashPromise = connection.getLatestBlockhash({
77
+ commitment: targetCommitment,
78
+ });
79
+ }
80
+ return latestBlockhashPromise;
81
+ }
82
+ const payloads = yield Promise.all(transactions.map((transaction) => __awaiter(this, void 0, void 0, function* () {
61
83
  if (transaction.feePayer == null) {
62
- transaction.feePayer = params.fee_payer;
84
+ transaction.feePayer = feePayer;
63
85
  }
64
86
  if (transaction.recentBlockhash == null) {
65
- const { blockhash } = yield getLatestBlockhash(params.connection);
87
+ const { blockhash } = yield getLatestBlockhashPromise();
66
88
  transaction.recentBlockhash = blockhash;
67
89
  }
68
90
  const serializedTransaction = transaction.serialize({
@@ -71,53 +93,36 @@ function transact(callback, config) {
71
93
  });
72
94
  return serializedTransaction.toString('base64');
73
95
  })));
74
- let targetCommitment;
75
- switch (params.connection.commitment) {
76
- case 'confirmed':
77
- case 'finalized':
78
- case 'processed':
79
- targetCommitment = params.connection.commitment;
80
- break;
81
- default:
82
- targetCommitment = 'finalized';
83
- }
84
- const { signatures } = yield wallet.signAndSendTransaction({
85
- auth_token: params.auth_token,
86
- commitment: targetCommitment,
87
- payloads,
88
- });
96
+ const { signatures: base64EncodedSignatures } = yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, rest), { commitment: targetCommitment, payloads, preflight_commitment: targetCommitment }));
97
+ const signatures = base64EncodedSignatures.map(toUint8Array).map(bs58.encode);
89
98
  return signatures;
90
99
  });
91
100
  };
92
101
  break;
93
- case 'signMessage':
94
- target[p] = function (params) {
102
+ case 'signMessages':
103
+ target[p] = function (_a) {
104
+ var { payloads } = _a, rest = __rest(_a, ["payloads"]);
95
105
  return __awaiter(this, void 0, void 0, function* () {
96
- const payloads = params.payloads.map(fromUint8Array);
97
- const { signed_payloads: base64EncodedSignedMessages } = yield wallet.signMessage({
98
- auth_token: params.auth_token,
99
- payloads,
100
- });
106
+ const base64EncodedPayloads = payloads.map(fromUint8Array);
107
+ const { signed_payloads: base64EncodedSignedMessages } = yield wallet.signMessages(Object.assign(Object.assign({}, rest), { payloads: base64EncodedPayloads }));
101
108
  const signedMessages = base64EncodedSignedMessages.map(toUint8Array);
102
109
  return signedMessages;
103
110
  });
104
111
  };
105
112
  break;
106
- case 'signTransaction':
107
- target[p] = function (params) {
113
+ case 'signTransactions':
114
+ target[p] = function (_a) {
115
+ var { transactions } = _a, rest = __rest(_a, ["transactions"]);
108
116
  return __awaiter(this, void 0, void 0, function* () {
109
- const serializedTransactions = params.transactions.map((transaction) => transaction.serialize({
117
+ const serializedTransactions = transactions.map((transaction) => transaction.serialize({
110
118
  requireAllSignatures: false,
111
119
  verifySignatures: false,
112
120
  }));
113
121
  const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
114
- const { signed_payloads: base64EncodedCompiledTransactions } = yield wallet.signTransaction({
115
- auth_token: params.auth_token,
116
- payloads,
117
- });
122
+ const { signed_payloads: base64EncodedCompiledTransactions } = yield wallet.signTransactions(Object.assign(Object.assign({}, rest), { payloads }));
118
123
  const compiledTransactions = base64EncodedCompiledTransactions.map(toUint8Array);
119
- const transactions = compiledTransactions.map(Transaction.from);
120
- return transactions;
124
+ const signedTransactions = compiledTransactions.map(Transaction.from);
125
+ return signedTransactions;
121
126
  });
122
127
  };
123
128
  break;
@@ -1,26 +1,23 @@
1
1
  import { Connection, PublicKey, Transaction, TransactionSignature } from "@solana/web3.js";
2
- import { AuthorizeAPI, AuthToken, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, WalletAssociationConfig } from "@solana-mobile/mobile-wallet-adapter-protocol";
3
- interface Web3SignAndSendTransactionAPI {
4
- signAndSendTransaction(params: {
5
- auth_token: AuthToken;
2
+ import { AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, WalletAssociationConfig } from "@solana-mobile/mobile-wallet-adapter-protocol";
3
+ interface Web3SignAndSendTransactionsAPI {
4
+ signAndSendTransactions(params: {
6
5
  connection: Connection;
7
6
  fee_payer?: PublicKey;
8
7
  transactions: Transaction[];
9
8
  }): Promise<TransactionSignature[]>;
10
9
  }
11
- interface Web3SignTransactionAPI {
12
- signTransaction(params: {
13
- auth_token: AuthToken;
10
+ interface Web3SignTransactionsAPI {
11
+ signTransactions(params: {
14
12
  transactions: Transaction[];
15
13
  }): Promise<Transaction[]>;
16
14
  }
17
- interface Web3SignMessageAPI {
18
- signMessage(params: {
19
- auth_token: AuthToken;
15
+ interface Web3SignMessagesAPI {
16
+ signMessages(params: {
20
17
  payloads: Uint8Array[];
21
18
  }): Promise<Uint8Array[]>;
22
19
  }
23
- interface Web3MobileWallet extends AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, Web3SignAndSendTransactionAPI, Web3SignTransactionAPI, Web3SignMessageAPI {
20
+ interface Web3MobileWallet extends AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, Web3SignAndSendTransactionsAPI, Web3SignTransactionsAPI, Web3SignMessagesAPI {
24
21
  }
25
22
  declare function transact<TReturn>(callback: (wallet: Web3MobileWallet) => TReturn, config?: WalletAssociationConfig): Promise<TReturn>;
26
23
  export { Web3MobileWallet, transact };
@@ -1,26 +1,23 @@
1
1
  import { Connection, PublicKey, Transaction, TransactionSignature } from "@solana/web3.js";
2
- import { AuthorizeAPI, AuthToken, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, WalletAssociationConfig } from "@solana-mobile/mobile-wallet-adapter-protocol";
3
- interface Web3SignAndSendTransactionAPI {
4
- signAndSendTransaction(params: {
5
- auth_token: AuthToken;
2
+ import { AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, WalletAssociationConfig } from "@solana-mobile/mobile-wallet-adapter-protocol";
3
+ interface Web3SignAndSendTransactionsAPI {
4
+ signAndSendTransactions(params: {
6
5
  connection: Connection;
7
6
  fee_payer?: PublicKey;
8
7
  transactions: Transaction[];
9
8
  }): Promise<TransactionSignature[]>;
10
9
  }
11
- interface Web3SignTransactionAPI {
12
- signTransaction(params: {
13
- auth_token: AuthToken;
10
+ interface Web3SignTransactionsAPI {
11
+ signTransactions(params: {
14
12
  transactions: Transaction[];
15
13
  }): Promise<Transaction[]>;
16
14
  }
17
- interface Web3SignMessageAPI {
18
- signMessage(params: {
19
- auth_token: AuthToken;
15
+ interface Web3SignMessagesAPI {
16
+ signMessages(params: {
20
17
  payloads: Uint8Array[];
21
18
  }): Promise<Uint8Array[]>;
22
19
  }
23
- interface Web3MobileWallet extends AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, Web3SignAndSendTransactionAPI, Web3SignTransactionAPI, Web3SignMessageAPI {
20
+ interface Web3MobileWallet extends AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, Web3SignAndSendTransactionsAPI, Web3SignTransactionsAPI, Web3SignMessagesAPI {
24
21
  }
25
22
  declare function transact<TReturn>(callback: (wallet: Web3MobileWallet) => TReturn, config?: WalletAssociationConfig): Promise<TReturn>;
26
23
  export { Web3MobileWallet, transact };
@@ -1,26 +1,23 @@
1
1
  import { Connection, PublicKey, Transaction, TransactionSignature } from "@solana/web3.js";
2
- import { AuthorizeAPI, AuthToken, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, WalletAssociationConfig } from "@solana-mobile/mobile-wallet-adapter-protocol";
3
- interface Web3SignAndSendTransactionAPI {
4
- signAndSendTransaction(params: {
5
- auth_token: AuthToken;
2
+ import { AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, WalletAssociationConfig } from "@solana-mobile/mobile-wallet-adapter-protocol";
3
+ interface Web3SignAndSendTransactionsAPI {
4
+ signAndSendTransactions(params: {
6
5
  connection: Connection;
7
6
  fee_payer?: PublicKey;
8
7
  transactions: Transaction[];
9
8
  }): Promise<TransactionSignature[]>;
10
9
  }
11
- interface Web3SignTransactionAPI {
12
- signTransaction(params: {
13
- auth_token: AuthToken;
10
+ interface Web3SignTransactionsAPI {
11
+ signTransactions(params: {
14
12
  transactions: Transaction[];
15
13
  }): Promise<Transaction[]>;
16
14
  }
17
- interface Web3SignMessageAPI {
18
- signMessage(params: {
19
- auth_token: AuthToken;
15
+ interface Web3SignMessagesAPI {
16
+ signMessages(params: {
20
17
  payloads: Uint8Array[];
21
18
  }): Promise<Uint8Array[]>;
22
19
  }
23
- interface Web3MobileWallet extends AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, Web3SignAndSendTransactionAPI, Web3SignTransactionAPI, Web3SignMessageAPI {
20
+ interface Web3MobileWallet extends AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, Web3SignAndSendTransactionsAPI, Web3SignTransactionsAPI, Web3SignMessagesAPI {
24
21
  }
25
22
  declare function transact<TReturn>(callback: (wallet: Web3MobileWallet) => TReturn, config?: WalletAssociationConfig): Promise<TReturn>;
26
23
  export { Web3MobileWallet, transact };
@@ -1,26 +1,23 @@
1
1
  import { Connection, PublicKey, Transaction, TransactionSignature } from "@solana/web3.js";
2
- import { AuthorizeAPI, AuthToken, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, WalletAssociationConfig } from "@solana-mobile/mobile-wallet-adapter-protocol";
3
- interface Web3SignAndSendTransactionAPI {
4
- signAndSendTransaction(params: {
5
- auth_token: AuthToken;
2
+ import { AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, WalletAssociationConfig } from "@solana-mobile/mobile-wallet-adapter-protocol";
3
+ interface Web3SignAndSendTransactionsAPI {
4
+ signAndSendTransactions(params: {
6
5
  connection: Connection;
7
6
  fee_payer?: PublicKey;
8
7
  transactions: Transaction[];
9
8
  }): Promise<TransactionSignature[]>;
10
9
  }
11
- interface Web3SignTransactionAPI {
12
- signTransaction(params: {
13
- auth_token: AuthToken;
10
+ interface Web3SignTransactionsAPI {
11
+ signTransactions(params: {
14
12
  transactions: Transaction[];
15
13
  }): Promise<Transaction[]>;
16
14
  }
17
- interface Web3SignMessageAPI {
18
- signMessage(params: {
19
- auth_token: AuthToken;
15
+ interface Web3SignMessagesAPI {
16
+ signMessages(params: {
20
17
  payloads: Uint8Array[];
21
18
  }): Promise<Uint8Array[]>;
22
19
  }
23
- interface Web3MobileWallet extends AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, Web3SignAndSendTransactionAPI, Web3SignTransactionAPI, Web3SignMessageAPI {
20
+ interface Web3MobileWallet extends AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, Web3SignAndSendTransactionsAPI, Web3SignTransactionsAPI, Web3SignMessagesAPI {
24
21
  }
25
22
  declare function transact<TReturn>(callback: (wallet: Web3MobileWallet) => TReturn, config?: WalletAssociationConfig): Promise<TReturn>;
26
23
  export { Web3MobileWallet, transact };
@@ -1,26 +1,23 @@
1
1
  import { Connection, PublicKey, Transaction, TransactionSignature } from "@solana/web3.js";
2
- import { AuthorizeAPI, AuthToken, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, WalletAssociationConfig } from "@solana-mobile/mobile-wallet-adapter-protocol";
3
- interface Web3SignAndSendTransactionAPI {
4
- signAndSendTransaction(params: {
5
- auth_token: AuthToken;
2
+ import { AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, WalletAssociationConfig } from "@solana-mobile/mobile-wallet-adapter-protocol";
3
+ interface Web3SignAndSendTransactionsAPI {
4
+ signAndSendTransactions(params: {
6
5
  connection: Connection;
7
6
  fee_payer?: PublicKey;
8
7
  transactions: Transaction[];
9
8
  }): Promise<TransactionSignature[]>;
10
9
  }
11
- interface Web3SignTransactionAPI {
12
- signTransaction(params: {
13
- auth_token: AuthToken;
10
+ interface Web3SignTransactionsAPI {
11
+ signTransactions(params: {
14
12
  transactions: Transaction[];
15
13
  }): Promise<Transaction[]>;
16
14
  }
17
- interface Web3SignMessageAPI {
18
- signMessage(params: {
19
- auth_token: AuthToken;
15
+ interface Web3SignMessagesAPI {
16
+ signMessages(params: {
20
17
  payloads: Uint8Array[];
21
18
  }): Promise<Uint8Array[]>;
22
19
  }
23
- interface Web3MobileWallet extends AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, Web3SignAndSendTransactionAPI, Web3SignTransactionAPI, Web3SignMessageAPI {
20
+ interface Web3MobileWallet extends AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, ReauthorizeAPI, Web3SignAndSendTransactionsAPI, Web3SignTransactionsAPI, Web3SignMessagesAPI {
24
21
  }
25
22
  declare function transact<TReturn>(callback: (wallet: Web3MobileWallet) => TReturn, config?: WalletAssociationConfig): Promise<TReturn>;
26
23
  export { Web3MobileWallet, transact };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@solana-mobile/mobile-wallet-adapter-protocol-web3js",
3
3
  "description": "A convenience wrapper that enables you to call Solana Mobile Stack protocol methods using objects from @solana/web3.js",
4
- "version": "0.0.1-alpha.7",
4
+ "version": "0.0.1-alpha.8",
5
5
  "author": "Steven Luscher <steven.luscher@solanamobile.com>",
6
6
  "repository": "https://github.com/solana-mobile/mobile-wallet-adapter",
7
7
  "license": "Apache-2.0",
@@ -40,11 +40,12 @@
40
40
  "@solana/web3.js": "^1.48.0"
41
41
  },
42
42
  "dependencies": {
43
- "@solana-mobile/mobile-wallet-adapter-protocol": "^0.0.1-alpha.7",
43
+ "@solana-mobile/mobile-wallet-adapter-protocol": "^0.0.1-alpha.8",
44
+ "bs58": "^5.0.0",
44
45
  "js-base64": "^3.7.2"
45
46
  },
46
47
  "devDependencies": {
47
48
  "agadoo": "^2.0.0"
48
49
  },
49
- "gitHead": "3af26689f4dddaa208fc32ea9c7cf4046c767c78"
50
+ "gitHead": "35529bd4ea1195ff7587f79105f2fb49d0e394b0"
50
51
  }