@solana-mobile/mobile-wallet-adapter-protocol-web3js 0.0.1-alpha.5 → 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.
- package/lib/cjs/index.browser.js +107 -76
- package/lib/cjs/index.js +107 -76
- package/lib/cjs/index.native.js +105 -83
- package/lib/esm/index.browser.mjs +103 -76
- package/lib/esm/index.mjs +103 -76
- package/lib/types/index.browser.d.mts +10 -13
- package/lib/types/index.browser.d.mts.map +1 -1
- package/lib/types/index.browser.d.ts +10 -13
- package/lib/types/index.browser.d.ts.map +1 -1
- package/lib/types/index.d.mts +10 -13
- package/lib/types/index.d.mts.map +1 -1
- package/lib/types/index.d.ts +10 -13
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.native.d.ts +10 -13
- package/lib/types/index.native.d.ts.map +1 -1
- package/package.json +5 -3
package/lib/cjs/index.browser.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) {
|
|
@@ -30,94 +47,108 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
30
47
|
});
|
|
31
48
|
}
|
|
32
49
|
|
|
33
|
-
function
|
|
50
|
+
function fromUint8Array(byteArray) {
|
|
34
51
|
return window.btoa(String.fromCharCode.call(null, ...byteArray));
|
|
35
52
|
}
|
|
36
|
-
function
|
|
53
|
+
function toUint8Array(base64EncodedByteArray) {
|
|
37
54
|
return new Uint8Array(window
|
|
38
55
|
.atob(base64EncodedByteArray)
|
|
39
56
|
.split('')
|
|
40
57
|
.map((c) => c.charCodeAt(0)));
|
|
41
58
|
}
|
|
59
|
+
|
|
42
60
|
function transact(callback, config) {
|
|
43
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const augmentedCallback = (
|
|
45
|
-
const augmentedAPI =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
62
|
+
const augmentedCallback = (wallet) => {
|
|
63
|
+
const augmentedAPI = new Proxy({}, {
|
|
64
|
+
get(target, p) {
|
|
65
|
+
if (target[p] == null) {
|
|
66
|
+
switch (p) {
|
|
67
|
+
case 'signAndSendTransactions':
|
|
68
|
+
target[p] = function (_a) {
|
|
69
|
+
var { connection, fee_payer: feePayer, transactions } = _a, rest = __rest(_a, ["connection", "fee_payer", "transactions"]);
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
let latestBlockhashPromise;
|
|
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';
|
|
81
|
+
}
|
|
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* () {
|
|
91
|
+
if (transaction.feePayer == null) {
|
|
92
|
+
transaction.feePayer = feePayer;
|
|
93
|
+
}
|
|
94
|
+
if (transaction.recentBlockhash == null) {
|
|
95
|
+
const { blockhash } = yield getLatestBlockhashPromise();
|
|
96
|
+
transaction.recentBlockhash = blockhash;
|
|
97
|
+
}
|
|
98
|
+
const serializedTransaction = transaction.serialize({
|
|
99
|
+
requireAllSignatures: false,
|
|
100
|
+
verifySignatures: false,
|
|
101
|
+
});
|
|
102
|
+
return serializedTransaction.toString('base64');
|
|
103
|
+
})));
|
|
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);
|
|
106
|
+
return signatures;
|
|
107
|
+
});
|
|
108
|
+
};
|
|
81
109
|
break;
|
|
82
|
-
|
|
83
|
-
|
|
110
|
+
case 'signMessages':
|
|
111
|
+
target[p] = function (_a) {
|
|
112
|
+
var { payloads } = _a, rest = __rest(_a, ["payloads"]);
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const base64EncodedPayloads = payloads.map(fromUint8Array);
|
|
115
|
+
const { signed_payloads: base64EncodedSignedMessages } = yield wallet.signMessages(Object.assign(Object.assign({}, rest), { payloads: base64EncodedPayloads }));
|
|
116
|
+
const signedMessages = base64EncodedSignedMessages.map(toUint8Array);
|
|
117
|
+
return signedMessages;
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
break;
|
|
121
|
+
case 'signTransactions':
|
|
122
|
+
target[p] = function (_a) {
|
|
123
|
+
var { transactions } = _a, rest = __rest(_a, ["transactions"]);
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const serializedTransactions = transactions.map((transaction) => transaction.serialize({
|
|
126
|
+
requireAllSignatures: false,
|
|
127
|
+
verifySignatures: false,
|
|
128
|
+
}));
|
|
129
|
+
const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
|
|
130
|
+
const { signed_payloads: base64EncodedCompiledTransactions } = yield wallet.signTransactions(Object.assign(Object.assign({}, rest), { payloads }));
|
|
131
|
+
const compiledTransactions = base64EncodedCompiledTransactions.map(toUint8Array);
|
|
132
|
+
const signedTransactions = compiledTransactions.map(web3_js.Transaction.from);
|
|
133
|
+
return signedTransactions;
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
break;
|
|
137
|
+
default: {
|
|
138
|
+
target[p] = wallet[p];
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
84
141
|
}
|
|
85
|
-
const { signatures } = yield walletAPI('sign_and_send_transaction', {
|
|
86
|
-
auth_token: params.auth_token,
|
|
87
|
-
commitment: targetCommitment,
|
|
88
|
-
payloads,
|
|
89
|
-
});
|
|
90
|
-
return signatures;
|
|
91
|
-
}
|
|
92
|
-
case 'sign_message': {
|
|
93
|
-
const params = args[1];
|
|
94
|
-
const payloads = params.payloads.map(getBase64StringFromByteArray);
|
|
95
|
-
const { signed_payloads: base64EncodedSignedMessages } = yield walletAPI('sign_message', {
|
|
96
|
-
auth_token: params.auth_token,
|
|
97
|
-
payloads,
|
|
98
|
-
});
|
|
99
|
-
const signedMessages = base64EncodedSignedMessages.map(getByteArrayFromBase64String);
|
|
100
|
-
return signedMessages;
|
|
101
|
-
}
|
|
102
|
-
case 'sign_transaction': {
|
|
103
|
-
const params = args[1];
|
|
104
|
-
const serializedTransactions = params.transactions.map((transaction) => transaction.serialize({
|
|
105
|
-
requireAllSignatures: false,
|
|
106
|
-
verifySignatures: false,
|
|
107
|
-
}));
|
|
108
|
-
const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
|
|
109
|
-
const { signed_payloads: base64EncodedCompiledTransactions } = yield walletAPI('sign_transaction', {
|
|
110
|
-
auth_token: params.auth_token,
|
|
111
|
-
payloads,
|
|
112
|
-
});
|
|
113
|
-
const compiledTransactions = base64EncodedCompiledTransactions.map(getByteArrayFromBase64String);
|
|
114
|
-
const transactions = compiledTransactions.map(web3_js.Transaction.from);
|
|
115
|
-
return transactions;
|
|
116
142
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
143
|
+
return target[p];
|
|
144
|
+
},
|
|
145
|
+
defineProperty() {
|
|
146
|
+
return false;
|
|
147
|
+
},
|
|
148
|
+
deleteProperty() {
|
|
149
|
+
return false;
|
|
150
|
+
},
|
|
151
|
+
});
|
|
121
152
|
return callback(augmentedAPI);
|
|
122
153
|
};
|
|
123
154
|
return yield mobileWalletAdapterProtocol.transact(augmentedCallback, config);
|
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) {
|
|
@@ -30,94 +47,108 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
30
47
|
});
|
|
31
48
|
}
|
|
32
49
|
|
|
33
|
-
function
|
|
50
|
+
function fromUint8Array(byteArray) {
|
|
34
51
|
return window.btoa(String.fromCharCode.call(null, ...byteArray));
|
|
35
52
|
}
|
|
36
|
-
function
|
|
53
|
+
function toUint8Array(base64EncodedByteArray) {
|
|
37
54
|
return new Uint8Array(window
|
|
38
55
|
.atob(base64EncodedByteArray)
|
|
39
56
|
.split('')
|
|
40
57
|
.map((c) => c.charCodeAt(0)));
|
|
41
58
|
}
|
|
59
|
+
|
|
42
60
|
function transact(callback, config) {
|
|
43
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const augmentedCallback = (
|
|
45
|
-
const augmentedAPI =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
62
|
+
const augmentedCallback = (wallet) => {
|
|
63
|
+
const augmentedAPI = new Proxy({}, {
|
|
64
|
+
get(target, p) {
|
|
65
|
+
if (target[p] == null) {
|
|
66
|
+
switch (p) {
|
|
67
|
+
case 'signAndSendTransactions':
|
|
68
|
+
target[p] = function (_a) {
|
|
69
|
+
var { connection, fee_payer: feePayer, transactions } = _a, rest = __rest(_a, ["connection", "fee_payer", "transactions"]);
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
let latestBlockhashPromise;
|
|
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';
|
|
81
|
+
}
|
|
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* () {
|
|
91
|
+
if (transaction.feePayer == null) {
|
|
92
|
+
transaction.feePayer = feePayer;
|
|
93
|
+
}
|
|
94
|
+
if (transaction.recentBlockhash == null) {
|
|
95
|
+
const { blockhash } = yield getLatestBlockhashPromise();
|
|
96
|
+
transaction.recentBlockhash = blockhash;
|
|
97
|
+
}
|
|
98
|
+
const serializedTransaction = transaction.serialize({
|
|
99
|
+
requireAllSignatures: false,
|
|
100
|
+
verifySignatures: false,
|
|
101
|
+
});
|
|
102
|
+
return serializedTransaction.toString('base64');
|
|
103
|
+
})));
|
|
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);
|
|
106
|
+
return signatures;
|
|
107
|
+
});
|
|
108
|
+
};
|
|
81
109
|
break;
|
|
82
|
-
|
|
83
|
-
|
|
110
|
+
case 'signMessages':
|
|
111
|
+
target[p] = function (_a) {
|
|
112
|
+
var { payloads } = _a, rest = __rest(_a, ["payloads"]);
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const base64EncodedPayloads = payloads.map(fromUint8Array);
|
|
115
|
+
const { signed_payloads: base64EncodedSignedMessages } = yield wallet.signMessages(Object.assign(Object.assign({}, rest), { payloads: base64EncodedPayloads }));
|
|
116
|
+
const signedMessages = base64EncodedSignedMessages.map(toUint8Array);
|
|
117
|
+
return signedMessages;
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
break;
|
|
121
|
+
case 'signTransactions':
|
|
122
|
+
target[p] = function (_a) {
|
|
123
|
+
var { transactions } = _a, rest = __rest(_a, ["transactions"]);
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const serializedTransactions = transactions.map((transaction) => transaction.serialize({
|
|
126
|
+
requireAllSignatures: false,
|
|
127
|
+
verifySignatures: false,
|
|
128
|
+
}));
|
|
129
|
+
const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
|
|
130
|
+
const { signed_payloads: base64EncodedCompiledTransactions } = yield wallet.signTransactions(Object.assign(Object.assign({}, rest), { payloads }));
|
|
131
|
+
const compiledTransactions = base64EncodedCompiledTransactions.map(toUint8Array);
|
|
132
|
+
const signedTransactions = compiledTransactions.map(web3_js.Transaction.from);
|
|
133
|
+
return signedTransactions;
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
break;
|
|
137
|
+
default: {
|
|
138
|
+
target[p] = wallet[p];
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
84
141
|
}
|
|
85
|
-
const { signatures } = yield walletAPI('sign_and_send_transaction', {
|
|
86
|
-
auth_token: params.auth_token,
|
|
87
|
-
commitment: targetCommitment,
|
|
88
|
-
payloads,
|
|
89
|
-
});
|
|
90
|
-
return signatures;
|
|
91
|
-
}
|
|
92
|
-
case 'sign_message': {
|
|
93
|
-
const params = args[1];
|
|
94
|
-
const payloads = params.payloads.map(getBase64StringFromByteArray);
|
|
95
|
-
const { signed_payloads: base64EncodedSignedMessages } = yield walletAPI('sign_message', {
|
|
96
|
-
auth_token: params.auth_token,
|
|
97
|
-
payloads,
|
|
98
|
-
});
|
|
99
|
-
const signedMessages = base64EncodedSignedMessages.map(getByteArrayFromBase64String);
|
|
100
|
-
return signedMessages;
|
|
101
|
-
}
|
|
102
|
-
case 'sign_transaction': {
|
|
103
|
-
const params = args[1];
|
|
104
|
-
const serializedTransactions = params.transactions.map((transaction) => transaction.serialize({
|
|
105
|
-
requireAllSignatures: false,
|
|
106
|
-
verifySignatures: false,
|
|
107
|
-
}));
|
|
108
|
-
const payloads = serializedTransactions.map((serializedTransaction) => serializedTransaction.toString('base64'));
|
|
109
|
-
const { signed_payloads: base64EncodedCompiledTransactions } = yield walletAPI('sign_transaction', {
|
|
110
|
-
auth_token: params.auth_token,
|
|
111
|
-
payloads,
|
|
112
|
-
});
|
|
113
|
-
const compiledTransactions = base64EncodedCompiledTransactions.map(getByteArrayFromBase64String);
|
|
114
|
-
const transactions = compiledTransactions.map(web3_js.Transaction.from);
|
|
115
|
-
return transactions;
|
|
116
142
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
143
|
+
return target[p];
|
|
144
|
+
},
|
|
145
|
+
defineProperty() {
|
|
146
|
+
return false;
|
|
147
|
+
},
|
|
148
|
+
deleteProperty() {
|
|
149
|
+
return false;
|
|
150
|
+
},
|
|
151
|
+
});
|
|
121
152
|
return callback(augmentedAPI);
|
|
122
153
|
};
|
|
123
154
|
return yield mobileWalletAdapterProtocol.transact(augmentedCallback, config);
|