@solana-mobile/mobile-wallet-adapter-protocol 2.2.7 → 2.2.9
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/android/build.gradle +2 -2
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +3 -1
- package/android/gradlew +1 -1
- package/android/gradlew.bat +10 -21
- package/lib/cjs/chunks/base58Utils.js +63 -0
- package/lib/cjs/chunks/base58Utils.js.map +1 -0
- package/lib/cjs/chunks/encoding.js +145 -0
- package/lib/cjs/chunks/encoding.js.map +1 -0
- package/lib/cjs/encoding.browser.js +12 -0
- package/lib/cjs/encoding.js +12 -0
- package/lib/cjs/encoding.native.js +49 -0
- package/lib/cjs/encoding.native.js.map +1 -0
- package/lib/cjs/index.browser.js +36 -63
- package/lib/cjs/index.browser.js.map +1 -1
- package/lib/cjs/index.js +36 -63
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/index.native.js +14 -20
- package/lib/cjs/index.native.js.map +1 -1
- package/lib/esm/chunks/encoding.js +62 -0
- package/lib/esm/chunks/encoding.js.map +1 -0
- package/lib/esm/encoding.browser.js +2 -0
- package/lib/esm/encoding.js +2 -0
- package/lib/esm/index.browser.js +30 -57
- package/lib/esm/index.browser.js.map +1 -1
- package/lib/esm/index.js +30 -57
- package/lib/esm/index.js.map +1 -1
- package/lib/types/encoding.d.ts +16 -0
- package/lib/types/encoding.d.ts.map +1 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +44 -21
- package/src/codegenSpec/NativeSolanaMobileWalletAdapter.ts +2 -0
package/lib/cjs/index.browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_encoding = require("./chunks/encoding.js");
|
|
2
3
|
let _solana_wallet_standard_util = require("@solana/wallet-standard-util");
|
|
3
|
-
let _solana_codecs_strings = require("@solana/codecs-strings");
|
|
4
4
|
//#region src/errors.ts
|
|
5
5
|
const SolanaMobileWalletAdapterErrorCode = {
|
|
6
6
|
ERROR_ASSOCIATION_PORT_OUT_OF_RANGE: "ERROR_ASSOCIATION_PORT_OUT_OF_RANGE",
|
|
@@ -48,19 +48,6 @@ var SolanaMobileWalletAdapterProtocolError = class extends Error {
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
//#endregion
|
|
51
|
-
//#region src/base64Utils.ts
|
|
52
|
-
function encode(input) {
|
|
53
|
-
return window.btoa(input);
|
|
54
|
-
}
|
|
55
|
-
function fromUint8Array$1(byteArray, urlsafe) {
|
|
56
|
-
const base64 = window.btoa(String.fromCharCode.call(null, ...byteArray));
|
|
57
|
-
if (urlsafe) return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
58
|
-
else return base64;
|
|
59
|
-
}
|
|
60
|
-
function toUint8Array(base64EncodedByteArray) {
|
|
61
|
-
return new Uint8Array(window.atob(base64EncodedByteArray).split("").map((c) => c.charCodeAt(0)));
|
|
62
|
-
}
|
|
63
|
-
//#endregion
|
|
64
51
|
//#region src/createHelloReq.ts
|
|
65
52
|
async function createHelloReq(ecdhPublicKey, associationKeypairPrivateKey) {
|
|
66
53
|
const publicKeyBuffer = await crypto.subtle.exportKey("raw", ecdhPublicKey);
|
|
@@ -79,7 +66,7 @@ function createSIWSMessage(payload) {
|
|
|
79
66
|
return (0, _solana_wallet_standard_util.createSignInMessageText)(payload);
|
|
80
67
|
}
|
|
81
68
|
function createSIWSMessageBase64Url(payload) {
|
|
82
|
-
return encode(createSIWSMessage(payload)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
69
|
+
return require_encoding.encode(createSIWSMessage(payload)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
83
70
|
}
|
|
84
71
|
//#endregion
|
|
85
72
|
//#region src/types.ts
|
|
@@ -87,14 +74,6 @@ const SolanaSignTransactions = "solana:signTransactions";
|
|
|
87
74
|
const SolanaCloneAuthorization = "solana:cloneAuthorization";
|
|
88
75
|
const SolanaSignInWithSolana = "solana:signInWithSolana";
|
|
89
76
|
//#endregion
|
|
90
|
-
//#region src/base58Utils.ts
|
|
91
|
-
function fromUint8Array(byteArray) {
|
|
92
|
-
return (0, _solana_codecs_strings.getBase58Decoder)().decode(byteArray);
|
|
93
|
-
}
|
|
94
|
-
function base64ToBase58(base64EncodedString) {
|
|
95
|
-
return fromUint8Array(toUint8Array(base64EncodedString));
|
|
96
|
-
}
|
|
97
|
-
//#endregion
|
|
98
77
|
//#region src/createMobileWalletProxy.ts
|
|
99
78
|
/**
|
|
100
79
|
* Creates a {@link MobileWallet} proxy that handles backwards compatibility and API to RPC conversion.
|
|
@@ -110,7 +89,7 @@ function createMobileWalletProxy(protocolVersion, protocolRequestHandler) {
|
|
|
110
89
|
if (target[p] == null) target[p] = async function(inputParams) {
|
|
111
90
|
const { method, params } = handleMobileWalletRequest(p, inputParams, protocolVersion);
|
|
112
91
|
const result = await protocolRequestHandler(method, params);
|
|
113
|
-
if (method === "authorize" && params.sign_in_payload && !result.sign_in_result) result
|
|
92
|
+
if (method === "authorize" && params.sign_in_payload && !result.sign_in_result) result.sign_in_result = await signInFallback(params.sign_in_payload, result, protocolRequestHandler);
|
|
114
93
|
return handleMobileWalletResponse(p, result, protocolVersion);
|
|
115
94
|
};
|
|
116
95
|
return target[p];
|
|
@@ -137,7 +116,8 @@ function handleMobileWalletRequest(methodName, methodParams, protocolVersion) {
|
|
|
137
116
|
let method = methodName.toString().replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`).toLowerCase();
|
|
138
117
|
switch (methodName) {
|
|
139
118
|
case "authorize": {
|
|
140
|
-
|
|
119
|
+
const authorizeParams = params;
|
|
120
|
+
let { chain } = authorizeParams;
|
|
141
121
|
if (protocolVersion === "legacy") {
|
|
142
122
|
switch (chain) {
|
|
143
123
|
case "solana:testnet":
|
|
@@ -149,9 +129,10 @@ function handleMobileWalletRequest(methodName, methodParams, protocolVersion) {
|
|
|
149
129
|
case "solana:mainnet":
|
|
150
130
|
chain = "mainnet-beta";
|
|
151
131
|
break;
|
|
152
|
-
default: chain =
|
|
132
|
+
default: chain = authorizeParams.cluster;
|
|
153
133
|
}
|
|
154
|
-
|
|
134
|
+
authorizeParams.cluster = chain;
|
|
135
|
+
params = authorizeParams;
|
|
155
136
|
} else {
|
|
156
137
|
switch (chain) {
|
|
157
138
|
case "testnet":
|
|
@@ -162,7 +143,8 @@ function handleMobileWalletRequest(methodName, methodParams, protocolVersion) {
|
|
|
162
143
|
chain = "solana:mainnet";
|
|
163
144
|
break;
|
|
164
145
|
}
|
|
165
|
-
|
|
146
|
+
authorizeParams.chain = chain;
|
|
147
|
+
params = authorizeParams;
|
|
166
148
|
}
|
|
167
149
|
}
|
|
168
150
|
case "reauthorize": {
|
|
@@ -224,14 +206,14 @@ async function signInFallback(signInPayload, authorizationResult, protocolReques
|
|
|
224
206
|
const siwsMessage = createSIWSMessageBase64Url({
|
|
225
207
|
...signInPayload,
|
|
226
208
|
domain,
|
|
227
|
-
address: base64ToBase58(address)
|
|
209
|
+
address: require_encoding.base64ToBase58$1(address)
|
|
228
210
|
});
|
|
229
|
-
const signedPayload = toUint8Array((await protocolRequestHandler("sign_messages", {
|
|
211
|
+
const signedPayload = require_encoding.toUint8Array((await protocolRequestHandler("sign_messages", {
|
|
230
212
|
addresses: [address],
|
|
231
213
|
payloads: [siwsMessage]
|
|
232
214
|
})).signed_payloads[0]);
|
|
233
|
-
const signedMessage = fromUint8Array
|
|
234
|
-
const signature = fromUint8Array
|
|
215
|
+
const signedMessage = require_encoding.fromUint8Array(signedPayload.slice(0, signedPayload.length - 64));
|
|
216
|
+
const signature = require_encoding.fromUint8Array(signedPayload.slice(signedPayload.length - 64));
|
|
235
217
|
return {
|
|
236
218
|
address,
|
|
237
219
|
signed_message: signedMessage.length == 0 ? siwsMessage : signedMessage,
|
|
@@ -251,7 +233,7 @@ async function encryptMessage(plaintext, sequenceNumber, sharedSecret) {
|
|
|
251
233
|
const sequenceNumberVector = createSequenceNumberVector(sequenceNumber);
|
|
252
234
|
const initializationVector = new Uint8Array(INITIALIZATION_VECTOR_BYTES);
|
|
253
235
|
crypto.getRandomValues(initializationVector);
|
|
254
|
-
const ciphertext = await crypto.subtle.encrypt(getAlgorithmParams(sequenceNumberVector, initializationVector), sharedSecret,
|
|
236
|
+
const ciphertext = await crypto.subtle.encrypt(getAlgorithmParams(sequenceNumberVector, initializationVector), sharedSecret, require_encoding.utf8ToUint8Array(plaintext));
|
|
255
237
|
const response = new Uint8Array(sequenceNumberVector.byteLength + initializationVector.byteLength + ciphertext.byteLength);
|
|
256
238
|
response.set(new Uint8Array(sequenceNumberVector), 0);
|
|
257
239
|
response.set(new Uint8Array(initializationVector), sequenceNumberVector.byteLength);
|
|
@@ -263,7 +245,7 @@ async function decryptMessage(message, sharedSecret) {
|
|
|
263
245
|
const initializationVector = message.slice(4, 4 + INITIALIZATION_VECTOR_BYTES);
|
|
264
246
|
const ciphertext = message.slice(4 + INITIALIZATION_VECTOR_BYTES);
|
|
265
247
|
const plaintextBuffer = await crypto.subtle.decrypt(getAlgorithmParams(sequenceNumberVector, initializationVector), sharedSecret, ciphertext);
|
|
266
|
-
return
|
|
248
|
+
return require_encoding.utf8FromUint8Array(new Uint8Array(plaintextBuffer));
|
|
267
249
|
}
|
|
268
250
|
function getAlgorithmParams(sequenceNumber, initializationVector) {
|
|
269
251
|
return {
|
|
@@ -273,11 +255,6 @@ function getAlgorithmParams(sequenceNumber, initializationVector) {
|
|
|
273
255
|
tagLength: 128
|
|
274
256
|
};
|
|
275
257
|
}
|
|
276
|
-
let _utf8Decoder;
|
|
277
|
-
function getUtf8Decoder() {
|
|
278
|
-
if (_utf8Decoder === void 0) _utf8Decoder = new TextDecoder("utf-8");
|
|
279
|
-
return _utf8Decoder;
|
|
280
|
-
}
|
|
281
258
|
//#endregion
|
|
282
259
|
//#region src/generateAssociationKeypair.ts
|
|
283
260
|
async function generateAssociationKeypair() {
|
|
@@ -295,15 +272,6 @@ async function generateECDHKeypair() {
|
|
|
295
272
|
}, false, ["deriveKey", "deriveBits"]);
|
|
296
273
|
}
|
|
297
274
|
//#endregion
|
|
298
|
-
//#region src/arrayBufferToBase64String.ts
|
|
299
|
-
function arrayBufferToBase64String(buffer) {
|
|
300
|
-
let binary = "";
|
|
301
|
-
const bytes = new Uint8Array(buffer);
|
|
302
|
-
const len = bytes.byteLength;
|
|
303
|
-
for (let ii = 0; ii < len; ii++) binary += String.fromCharCode(bytes[ii]);
|
|
304
|
-
return window.btoa(binary);
|
|
305
|
-
}
|
|
306
|
-
//#endregion
|
|
307
275
|
//#region src/associationPort.ts
|
|
308
276
|
function getRandomAssociationPort() {
|
|
309
277
|
return assertAssociationPort(49152 + Math.floor(Math.random() * 16384));
|
|
@@ -314,7 +282,7 @@ function assertAssociationPort(port) {
|
|
|
314
282
|
}
|
|
315
283
|
//#endregion
|
|
316
284
|
//#region src/getStringWithURLUnsafeBase64CharactersReplaced.ts
|
|
317
|
-
function
|
|
285
|
+
function getStringWithURLUnsafeBase64CharactersReplaced(unsafeBase64EncodedString) {
|
|
318
286
|
return unsafeBase64EncodedString.replace(/[/+=]/g, (m) => ({
|
|
319
287
|
"/": "_",
|
|
320
288
|
"+": "-",
|
|
@@ -341,9 +309,9 @@ function getIntentURL(methodPathname, intentUrlBase) {
|
|
|
341
309
|
}
|
|
342
310
|
async function getAssociateAndroidIntentURL(associationPublicKey, putativePort, associationURLBase, protocolVersions = ["v1"]) {
|
|
343
311
|
const associationPort = assertAssociationPort(putativePort);
|
|
344
|
-
const encodedKey = arrayBufferToBase64String(await crypto.subtle.exportKey("raw", associationPublicKey));
|
|
312
|
+
const encodedKey = require_encoding.arrayBufferToBase64String(await crypto.subtle.exportKey("raw", associationPublicKey));
|
|
345
313
|
const url = getIntentURL("v1/associate/local", associationURLBase);
|
|
346
|
-
url.searchParams.set("association",
|
|
314
|
+
url.searchParams.set("association", getStringWithURLUnsafeBase64CharactersReplaced(encodedKey));
|
|
347
315
|
url.searchParams.set("port", `${associationPort}`);
|
|
348
316
|
protocolVersions.forEach((version) => {
|
|
349
317
|
url.searchParams.set("v", version);
|
|
@@ -351,11 +319,11 @@ async function getAssociateAndroidIntentURL(associationPublicKey, putativePort,
|
|
|
351
319
|
return url;
|
|
352
320
|
}
|
|
353
321
|
async function getRemoteAssociateAndroidIntentURL(associationPublicKey, hostAuthority, reflectorId, associationURLBase, protocolVersions = ["v1"]) {
|
|
354
|
-
const encodedKey = arrayBufferToBase64String(await crypto.subtle.exportKey("raw", associationPublicKey));
|
|
322
|
+
const encodedKey = require_encoding.arrayBufferToBase64String(await crypto.subtle.exportKey("raw", associationPublicKey));
|
|
355
323
|
const url = getIntentURL("v1/associate/remote", associationURLBase);
|
|
356
|
-
url.searchParams.set("association",
|
|
324
|
+
url.searchParams.set("association", getStringWithURLUnsafeBase64CharactersReplaced(encodedKey));
|
|
357
325
|
url.searchParams.set("reflector", `${hostAuthority}`);
|
|
358
|
-
url.searchParams.set("id", `${fromUint8Array
|
|
326
|
+
url.searchParams.set("id", `${require_encoding.fromUint8Array(reflectorId, true)}`);
|
|
359
327
|
protocolVersions.forEach((version) => {
|
|
360
328
|
url.searchParams.set("v", version);
|
|
361
329
|
});
|
|
@@ -469,7 +437,7 @@ async function launchAssociation(associationUrl) {
|
|
|
469
437
|
}
|
|
470
438
|
default: assertUnreachable(browser);
|
|
471
439
|
}
|
|
472
|
-
} catch
|
|
440
|
+
} catch {
|
|
473
441
|
throw new SolanaMobileWalletAdapterError(SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND, "Found no installed wallet that supports the mobile wallet protocol.");
|
|
474
442
|
}
|
|
475
443
|
}
|
|
@@ -511,7 +479,10 @@ function getSequenceNumberFromByteArray(byteArray) {
|
|
|
511
479
|
return new DataView(byteArray).getUint32(0, false);
|
|
512
480
|
}
|
|
513
481
|
function decodeVarLong(byteArray) {
|
|
514
|
-
|
|
482
|
+
const bytes = new Uint8Array(byteArray);
|
|
483
|
+
const l = byteArray.byteLength;
|
|
484
|
+
const limit = 10;
|
|
485
|
+
let value = 0, offset = 0, b;
|
|
515
486
|
do {
|
|
516
487
|
if (offset >= l || offset > limit) throw new RangeError("Failed to decode varint");
|
|
517
488
|
b = bytes[offset++];
|
|
@@ -523,7 +494,7 @@ function decodeVarLong(byteArray) {
|
|
|
523
494
|
};
|
|
524
495
|
}
|
|
525
496
|
function getReflectorIdFromByteArray(byteArray) {
|
|
526
|
-
|
|
497
|
+
const { value: length, offset } = decodeVarLong(byteArray);
|
|
527
498
|
return new Uint8Array(byteArray.slice(offset, offset + length));
|
|
528
499
|
}
|
|
529
500
|
async function transact(callback, config) {
|
|
@@ -590,7 +561,7 @@ async function startScenario(config) {
|
|
|
590
561
|
const handleMessage = async (evt) => {
|
|
591
562
|
const responseBuffer = await evt.data.arrayBuffer();
|
|
592
563
|
switch (state.__type) {
|
|
593
|
-
case "connecting":
|
|
564
|
+
case "connecting": {
|
|
594
565
|
if (responseBuffer.byteLength !== 0) throw new Error("Encountered unexpected message while connecting");
|
|
595
566
|
const ecdhKeypair = await generateECDHKeypair();
|
|
596
567
|
socket.send(await createHelloReq(ecdhKeypair.publicKey, associationKeypair.privateKey));
|
|
@@ -600,6 +571,7 @@ async function startScenario(config) {
|
|
|
600
571
|
ecdhPrivateKey: ecdhKeypair.privateKey
|
|
601
572
|
};
|
|
602
573
|
break;
|
|
574
|
+
}
|
|
603
575
|
case "connected":
|
|
604
576
|
try {
|
|
605
577
|
const sequenceNumber = getSequenceNumberFromByteArray(responseBuffer.slice(0, 4));
|
|
@@ -727,8 +699,8 @@ async function startRemoteScenario(config) {
|
|
|
727
699
|
let state = { __type: "disconnected" };
|
|
728
700
|
let socket;
|
|
729
701
|
let disposeSocket;
|
|
730
|
-
|
|
731
|
-
if (encoding == "base64") return toUint8Array(await evt.data).buffer;
|
|
702
|
+
const decodeBytes = async (evt) => {
|
|
703
|
+
if (encoding == "base64") return require_encoding.toUint8Array(await evt.data).buffer;
|
|
732
704
|
else return await evt.data.arrayBuffer();
|
|
733
705
|
};
|
|
734
706
|
const associationUrl = await new Promise((resolve, reject) => {
|
|
@@ -807,11 +779,11 @@ async function startRemoteScenario(config) {
|
|
|
807
779
|
const handleMessage = async (evt) => {
|
|
808
780
|
const responseBuffer = await decodeBytes(evt);
|
|
809
781
|
switch (state.__type) {
|
|
810
|
-
case "reflector_id_received":
|
|
782
|
+
case "reflector_id_received": {
|
|
811
783
|
if (responseBuffer.byteLength !== 0) throw new Error("Encountered unexpected message while awaiting reflection");
|
|
812
784
|
const ecdhKeypair = await generateECDHKeypair();
|
|
813
785
|
const binaryMsg = await createHelloReq(ecdhKeypair.publicKey, associationKeypair.privateKey);
|
|
814
|
-
if (encoding == "base64") socket.send(fromUint8Array
|
|
786
|
+
if (encoding == "base64") socket.send(require_encoding.fromUint8Array(binaryMsg));
|
|
815
787
|
else socket.send(binaryMsg);
|
|
816
788
|
state = {
|
|
817
789
|
__type: "hello_req_sent",
|
|
@@ -819,6 +791,7 @@ async function startRemoteScenario(config) {
|
|
|
819
791
|
ecdhPrivateKey: ecdhKeypair.privateKey
|
|
820
792
|
};
|
|
821
793
|
break;
|
|
794
|
+
}
|
|
822
795
|
case "connected":
|
|
823
796
|
try {
|
|
824
797
|
const sequenceNumber = getSequenceNumberFromByteArray(responseBuffer.slice(0, 4));
|
|
@@ -858,7 +831,7 @@ async function startRemoteScenario(config) {
|
|
|
858
831
|
method,
|
|
859
832
|
params: params ?? {}
|
|
860
833
|
}, sharedSecret);
|
|
861
|
-
if (encoding == "base64") socket.send(fromUint8Array
|
|
834
|
+
if (encoding == "base64") socket.send(require_encoding.fromUint8Array(binaryMsg));
|
|
862
835
|
else socket.send(binaryMsg);
|
|
863
836
|
return new Promise((resolve, reject) => {
|
|
864
837
|
jsonRpcResponsePromises[id] = {
|