@solana-mobile/mobile-wallet-adapter-protocol 0.0.1-alpha.1 → 0.0.1-alpha.5

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/README.md CHANGED
@@ -9,17 +9,17 @@ If you are simply looking to integrate a JavaScript application with mobile wall
9
9
  Use this API to start a session:
10
10
 
11
11
  ```typescript
12
- import {withLocalWallet} from '@solana-mobile/mobile-wallet-adapter-protocol';
12
+ import {transact} from '@solana-mobile/mobile-wallet-adapter-protocol';
13
13
 
14
- await withLocalWallet(async (wallet) => {
14
+ await transact(async (wallet) => {
15
15
  /* ... */
16
16
  });
17
17
  ```
18
18
 
19
- The callback you provide will be called once a session has been established with a wallet. It will recieve the `MobileWallet` API as an argument. You can call protocol-specified methods using this function. Whatever you return from this callback will be returned by `withLocalWallet`.
19
+ The callback you provide will be called once a session has been established with a wallet. It will recieve the `MobileWallet` API as an argument. You can call protocol-specified methods using this function. Whatever you return from this callback will be returned by `transact`.
20
20
 
21
21
  ```typescript
22
- const signedPayloads = await withLocalWallet(async (wallet) => {
22
+ const signedPayloads = await transact(async (wallet) => {
23
23
  const {signed_payloads} = await wallet('sign_message', {
24
24
  auth_token,
25
25
  payloads: [/* ... */],
@@ -36,7 +36,7 @@ You can catch exceptions at any level. See `errors.ts` for a list of exceptions
36
36
 
37
37
  ```typescript
38
38
  try {
39
- await withLocalWallet(async (wallet) => {
39
+ await transact(async (wallet) => {
40
40
  try {
41
41
  await wallet('sign_transaction', /* ... */);
42
42
  } catch (e) {
@@ -2,42 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- /******************************************************************************
6
- Copyright (c) Microsoft Corporation.
7
-
8
- Permission to use, copy, modify, and/or distribute this software for any
9
- purpose with or without fee is hereby granted.
10
-
11
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
- PERFORMANCE OF THIS SOFTWARE.
18
- ***************************************************************************** */
19
-
20
- function __awaiter(thisArg, _arguments, P, generator) {
21
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22
- return new (P || (P = Promise))(function (resolve, reject) {
23
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
25
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26
- step((generator = generator.apply(thisArg, _arguments || [])).next());
27
- });
28
- }
29
-
30
- function createHelloReq(ecdhPublicKey, associationKeypairPrivateKey) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const publicKeyBuffer = yield crypto.subtle.exportKey('raw', ecdhPublicKey);
33
- const signatureBuffer = yield crypto.subtle.sign({ hash: 'SHA-256', name: 'ECDSA' }, associationKeypairPrivateKey, publicKeyBuffer);
34
- const response = new Uint8Array(publicKeyBuffer.byteLength + signatureBuffer.byteLength);
35
- response.set(new Uint8Array(publicKeyBuffer), 0);
36
- response.set(new Uint8Array(signatureBuffer), publicKeyBuffer.byteLength);
37
- return response;
38
- });
39
- }
40
-
41
5
  class SolanaMobileWalletAdapterSecureContextRequiredError extends Error {
42
6
  constructor() {
43
7
  super('The mobile wallet adapter protocol must be used in a secure context (`https`).');
@@ -100,6 +64,42 @@ class SolanaMobileWalletAdapterProtocolJsonRpcError extends Error {
100
64
  }
101
65
  }
102
66
 
67
+ /******************************************************************************
68
+ Copyright (c) Microsoft Corporation.
69
+
70
+ Permission to use, copy, modify, and/or distribute this software for any
71
+ purpose with or without fee is hereby granted.
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
74
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
75
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
76
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
77
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
78
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
79
+ PERFORMANCE OF THIS SOFTWARE.
80
+ ***************************************************************************** */
81
+
82
+ function __awaiter(thisArg, _arguments, P, generator) {
83
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
84
+ return new (P || (P = Promise))(function (resolve, reject) {
85
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
86
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
87
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
88
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
89
+ });
90
+ }
91
+
92
+ function createHelloReq(ecdhPublicKey, associationKeypairPrivateKey) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ const publicKeyBuffer = yield crypto.subtle.exportKey('raw', ecdhPublicKey);
95
+ const signatureBuffer = yield crypto.subtle.sign({ hash: 'SHA-256', name: 'ECDSA' }, associationKeypairPrivateKey, publicKeyBuffer);
96
+ const response = new Uint8Array(publicKeyBuffer.byteLength + signatureBuffer.byteLength);
97
+ response.set(new Uint8Array(publicKeyBuffer), 0);
98
+ response.set(new Uint8Array(signatureBuffer), publicKeyBuffer.byteLength);
99
+ return response;
100
+ });
101
+ }
102
+
103
103
  function generateAssociationKeypair() {
104
104
  return __awaiter(this, void 0, void 0, function* () {
105
105
  return yield crypto.subtle.generateKey({
@@ -342,7 +342,7 @@ function assertSecureContext() {
342
342
  throw new SolanaMobileWalletAdapterSecureContextRequiredError();
343
343
  }
344
344
  }
345
- function withLocalWallet(callback, config) {
345
+ function transact(callback, config) {
346
346
  return __awaiter(this, void 0, void 0, function* () {
347
347
  assertSecureContext();
348
348
  const associationKeypair = yield generateAssociationKeypair();
@@ -416,7 +416,7 @@ function withLocalWallet(callback, config) {
416
416
  case 'hello_req_sent': {
417
417
  const sharedSecret = yield parseHelloRsp(responseBuffer, state.associationPublicKey, state.ecdhPrivateKey);
418
418
  state = { __type: 'connected', sharedSecret };
419
- const wallet = (method, params) => __awaiter(this, void 0, void 0, function* () {
419
+ const walletAPI = (method, params) => __awaiter(this, void 0, void 0, function* () {
420
420
  const id = nextJsonRpcMessageId++;
421
421
  socket.send(yield encryptJsonRpcMessage({
422
422
  id,
@@ -429,7 +429,7 @@ function withLocalWallet(callback, config) {
429
429
  });
430
430
  });
431
431
  try {
432
- resolve(yield callback(wallet));
432
+ resolve(yield callback(walletAPI));
433
433
  }
434
434
  catch (e) {
435
435
  reject(e);
@@ -476,4 +476,4 @@ exports.SolanaMobileWalletAdapterProtocolSessionClosedError = SolanaMobileWallet
476
476
  exports.SolanaMobileWalletAdapterProtocolSessionEstablishmentError = SolanaMobileWalletAdapterProtocolSessionEstablishmentError;
477
477
  exports.SolanaMobileWalletAdapterSecureContextRequiredError = SolanaMobileWalletAdapterSecureContextRequiredError;
478
478
  exports.SolanaMobileWalletAdapterWalletNotInstalledError = SolanaMobileWalletAdapterWalletNotInstalledError;
479
- exports.withLocalWallet = withLocalWallet;
479
+ exports.transact = transact;
package/lib/cjs/index.js CHANGED
@@ -2,42 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- /******************************************************************************
6
- Copyright (c) Microsoft Corporation.
7
-
8
- Permission to use, copy, modify, and/or distribute this software for any
9
- purpose with or without fee is hereby granted.
10
-
11
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
- PERFORMANCE OF THIS SOFTWARE.
18
- ***************************************************************************** */
19
-
20
- function __awaiter(thisArg, _arguments, P, generator) {
21
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22
- return new (P || (P = Promise))(function (resolve, reject) {
23
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
25
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26
- step((generator = generator.apply(thisArg, _arguments || [])).next());
27
- });
28
- }
29
-
30
- function createHelloReq(ecdhPublicKey, associationKeypairPrivateKey) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const publicKeyBuffer = yield crypto.subtle.exportKey('raw', ecdhPublicKey);
33
- const signatureBuffer = yield crypto.subtle.sign({ hash: 'SHA-256', name: 'ECDSA' }, associationKeypairPrivateKey, publicKeyBuffer);
34
- const response = new Uint8Array(publicKeyBuffer.byteLength + signatureBuffer.byteLength);
35
- response.set(new Uint8Array(publicKeyBuffer), 0);
36
- response.set(new Uint8Array(signatureBuffer), publicKeyBuffer.byteLength);
37
- return response;
38
- });
39
- }
40
-
41
5
  class SolanaMobileWalletAdapterSecureContextRequiredError extends Error {
42
6
  constructor() {
43
7
  super('The mobile wallet adapter protocol must be used in a secure context (`https`).');
@@ -100,6 +64,42 @@ class SolanaMobileWalletAdapterProtocolJsonRpcError extends Error {
100
64
  }
101
65
  }
102
66
 
67
+ /******************************************************************************
68
+ Copyright (c) Microsoft Corporation.
69
+
70
+ Permission to use, copy, modify, and/or distribute this software for any
71
+ purpose with or without fee is hereby granted.
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
74
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
75
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
76
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
77
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
78
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
79
+ PERFORMANCE OF THIS SOFTWARE.
80
+ ***************************************************************************** */
81
+
82
+ function __awaiter(thisArg, _arguments, P, generator) {
83
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
84
+ return new (P || (P = Promise))(function (resolve, reject) {
85
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
86
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
87
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
88
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
89
+ });
90
+ }
91
+
92
+ function createHelloReq(ecdhPublicKey, associationKeypairPrivateKey) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ const publicKeyBuffer = yield crypto.subtle.exportKey('raw', ecdhPublicKey);
95
+ const signatureBuffer = yield crypto.subtle.sign({ hash: 'SHA-256', name: 'ECDSA' }, associationKeypairPrivateKey, publicKeyBuffer);
96
+ const response = new Uint8Array(publicKeyBuffer.byteLength + signatureBuffer.byteLength);
97
+ response.set(new Uint8Array(publicKeyBuffer), 0);
98
+ response.set(new Uint8Array(signatureBuffer), publicKeyBuffer.byteLength);
99
+ return response;
100
+ });
101
+ }
102
+
103
103
  function generateAssociationKeypair() {
104
104
  return __awaiter(this, void 0, void 0, function* () {
105
105
  return yield crypto.subtle.generateKey({
@@ -342,7 +342,7 @@ function assertSecureContext() {
342
342
  throw new SolanaMobileWalletAdapterSecureContextRequiredError();
343
343
  }
344
344
  }
345
- function withLocalWallet(callback, config) {
345
+ function transact(callback, config) {
346
346
  return __awaiter(this, void 0, void 0, function* () {
347
347
  assertSecureContext();
348
348
  const associationKeypair = yield generateAssociationKeypair();
@@ -416,7 +416,7 @@ function withLocalWallet(callback, config) {
416
416
  case 'hello_req_sent': {
417
417
  const sharedSecret = yield parseHelloRsp(responseBuffer, state.associationPublicKey, state.ecdhPrivateKey);
418
418
  state = { __type: 'connected', sharedSecret };
419
- const wallet = (method, params) => __awaiter(this, void 0, void 0, function* () {
419
+ const walletAPI = (method, params) => __awaiter(this, void 0, void 0, function* () {
420
420
  const id = nextJsonRpcMessageId++;
421
421
  socket.send(yield encryptJsonRpcMessage({
422
422
  id,
@@ -429,7 +429,7 @@ function withLocalWallet(callback, config) {
429
429
  });
430
430
  });
431
431
  try {
432
- resolve(yield callback(wallet));
432
+ resolve(yield callback(walletAPI));
433
433
  }
434
434
  catch (e) {
435
435
  reject(e);
@@ -476,4 +476,4 @@ exports.SolanaMobileWalletAdapterProtocolSessionClosedError = SolanaMobileWallet
476
476
  exports.SolanaMobileWalletAdapterProtocolSessionEstablishmentError = SolanaMobileWalletAdapterProtocolSessionEstablishmentError;
477
477
  exports.SolanaMobileWalletAdapterSecureContextRequiredError = SolanaMobileWalletAdapterSecureContextRequiredError;
478
478
  exports.SolanaMobileWalletAdapterWalletNotInstalledError = SolanaMobileWalletAdapterWalletNotInstalledError;
479
- exports.withLocalWallet = withLocalWallet;
479
+ exports.transact = transact;
@@ -4,31 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var reactNative = require('react-native');
6
6
 
7
- /******************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
-
22
- function __awaiter(thisArg, _arguments, P, generator) {
23
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
- return new (P || (P = Promise))(function (resolve, reject) {
25
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
27
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28
- step((generator = generator.apply(thisArg, _arguments || [])).next());
29
- });
30
- }
31
-
32
7
  class SolanaMobileWalletAdapterSecureContextRequiredError extends Error {
33
8
  constructor() {
34
9
  super('The mobile wallet adapter protocol must be used in a secure context (`https`).');
@@ -91,6 +66,31 @@ class SolanaMobileWalletAdapterProtocolJsonRpcError extends Error {
91
66
  }
92
67
  }
93
68
 
69
+ /******************************************************************************
70
+ Copyright (c) Microsoft Corporation.
71
+
72
+ Permission to use, copy, modify, and/or distribute this software for any
73
+ purpose with or without fee is hereby granted.
74
+
75
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
76
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
77
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
78
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
79
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
80
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
81
+ PERFORMANCE OF THIS SOFTWARE.
82
+ ***************************************************************************** */
83
+
84
+ function __awaiter(thisArg, _arguments, P, generator) {
85
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
86
+ return new (P || (P = Promise))(function (resolve, reject) {
87
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
88
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
89
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
90
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
91
+ });
92
+ }
93
+
94
94
  const LINKING_ERROR = `The package 'solana-mobile-wallet-adapter-protocol' doesn't seem to be linked. Make sure: \n\n` +
95
95
  '- You rebuilt the app after installing the package\n' +
96
96
  '- If you are using Lerna workspaces\n' +
@@ -106,7 +106,7 @@ const SolanaMobileWalletAdapter = reactNative.Platform.OS === 'android' && react
106
106
  : LINKING_ERROR);
107
107
  },
108
108
  });
109
- function withLocalWallet(callback, config) {
109
+ function transact(callback, config) {
110
110
  return __awaiter(this, void 0, void 0, function* () {
111
111
  try {
112
112
  yield SolanaMobileWalletAdapter.startSession(config);
@@ -138,4 +138,4 @@ exports.SolanaMobileWalletAdapterProtocolSessionClosedError = SolanaMobileWallet
138
138
  exports.SolanaMobileWalletAdapterProtocolSessionEstablishmentError = SolanaMobileWalletAdapterProtocolSessionEstablishmentError;
139
139
  exports.SolanaMobileWalletAdapterSecureContextRequiredError = SolanaMobileWalletAdapterSecureContextRequiredError;
140
140
  exports.SolanaMobileWalletAdapterWalletNotInstalledError = SolanaMobileWalletAdapterWalletNotInstalledError;
141
- exports.withLocalWallet = withLocalWallet;
141
+ exports.transact = transact;
@@ -1,39 +1,3 @@
1
- /******************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
-
16
- function __awaiter(thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- }
25
-
26
- function createHelloReq(ecdhPublicKey, associationKeypairPrivateKey) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const publicKeyBuffer = yield crypto.subtle.exportKey('raw', ecdhPublicKey);
29
- const signatureBuffer = yield crypto.subtle.sign({ hash: 'SHA-256', name: 'ECDSA' }, associationKeypairPrivateKey, publicKeyBuffer);
30
- const response = new Uint8Array(publicKeyBuffer.byteLength + signatureBuffer.byteLength);
31
- response.set(new Uint8Array(publicKeyBuffer), 0);
32
- response.set(new Uint8Array(signatureBuffer), publicKeyBuffer.byteLength);
33
- return response;
34
- });
35
- }
36
-
37
1
  class SolanaMobileWalletAdapterSecureContextRequiredError extends Error {
38
2
  constructor() {
39
3
  super('The mobile wallet adapter protocol must be used in a secure context (`https`).');
@@ -96,6 +60,42 @@ class SolanaMobileWalletAdapterProtocolJsonRpcError extends Error {
96
60
  }
97
61
  }
98
62
 
63
+ /******************************************************************************
64
+ Copyright (c) Microsoft Corporation.
65
+
66
+ Permission to use, copy, modify, and/or distribute this software for any
67
+ purpose with or without fee is hereby granted.
68
+
69
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
70
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
71
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
72
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
73
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
74
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
75
+ PERFORMANCE OF THIS SOFTWARE.
76
+ ***************************************************************************** */
77
+
78
+ function __awaiter(thisArg, _arguments, P, generator) {
79
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
80
+ return new (P || (P = Promise))(function (resolve, reject) {
81
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
82
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
83
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
84
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
85
+ });
86
+ }
87
+
88
+ function createHelloReq(ecdhPublicKey, associationKeypairPrivateKey) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ const publicKeyBuffer = yield crypto.subtle.exportKey('raw', ecdhPublicKey);
91
+ const signatureBuffer = yield crypto.subtle.sign({ hash: 'SHA-256', name: 'ECDSA' }, associationKeypairPrivateKey, publicKeyBuffer);
92
+ const response = new Uint8Array(publicKeyBuffer.byteLength + signatureBuffer.byteLength);
93
+ response.set(new Uint8Array(publicKeyBuffer), 0);
94
+ response.set(new Uint8Array(signatureBuffer), publicKeyBuffer.byteLength);
95
+ return response;
96
+ });
97
+ }
98
+
99
99
  function generateAssociationKeypair() {
100
100
  return __awaiter(this, void 0, void 0, function* () {
101
101
  return yield crypto.subtle.generateKey({
@@ -338,7 +338,7 @@ function assertSecureContext() {
338
338
  throw new SolanaMobileWalletAdapterSecureContextRequiredError();
339
339
  }
340
340
  }
341
- function withLocalWallet(callback, config) {
341
+ function transact(callback, config) {
342
342
  return __awaiter(this, void 0, void 0, function* () {
343
343
  assertSecureContext();
344
344
  const associationKeypair = yield generateAssociationKeypair();
@@ -412,7 +412,7 @@ function withLocalWallet(callback, config) {
412
412
  case 'hello_req_sent': {
413
413
  const sharedSecret = yield parseHelloRsp(responseBuffer, state.associationPublicKey, state.ecdhPrivateKey);
414
414
  state = { __type: 'connected', sharedSecret };
415
- const wallet = (method, params) => __awaiter(this, void 0, void 0, function* () {
415
+ const walletAPI = (method, params) => __awaiter(this, void 0, void 0, function* () {
416
416
  const id = nextJsonRpcMessageId++;
417
417
  socket.send(yield encryptJsonRpcMessage({
418
418
  id,
@@ -425,7 +425,7 @@ function withLocalWallet(callback, config) {
425
425
  });
426
426
  });
427
427
  try {
428
- resolve(yield callback(wallet));
428
+ resolve(yield callback(walletAPI));
429
429
  }
430
430
  catch (e) {
431
431
  reject(e);
@@ -463,4 +463,4 @@ function withLocalWallet(callback, config) {
463
463
  });
464
464
  }
465
465
 
466
- export { SolanaMobileWalletAdapterForbiddenWalletBaseURLError, SolanaMobileWalletAdapterProtocolAssociationPortOutOfRangeError, SolanaMobileWalletAdapterProtocolError, SolanaMobileWalletAdapterProtocolJsonRpcError, SolanaMobileWalletAdapterProtocolReauthorizeError, SolanaMobileWalletAdapterProtocolSessionClosedError, SolanaMobileWalletAdapterProtocolSessionEstablishmentError, SolanaMobileWalletAdapterSecureContextRequiredError, SolanaMobileWalletAdapterWalletNotInstalledError, withLocalWallet };
466
+ export { SolanaMobileWalletAdapterForbiddenWalletBaseURLError, SolanaMobileWalletAdapterProtocolAssociationPortOutOfRangeError, SolanaMobileWalletAdapterProtocolError, SolanaMobileWalletAdapterProtocolJsonRpcError, SolanaMobileWalletAdapterProtocolReauthorizeError, SolanaMobileWalletAdapterProtocolSessionClosedError, SolanaMobileWalletAdapterProtocolSessionEstablishmentError, SolanaMobileWalletAdapterSecureContextRequiredError, SolanaMobileWalletAdapterWalletNotInstalledError, transact };
package/lib/esm/index.mjs CHANGED
@@ -1,39 +1,3 @@
1
- /******************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
-
16
- function __awaiter(thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- }
25
-
26
- function createHelloReq(ecdhPublicKey, associationKeypairPrivateKey) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const publicKeyBuffer = yield crypto.subtle.exportKey('raw', ecdhPublicKey);
29
- const signatureBuffer = yield crypto.subtle.sign({ hash: 'SHA-256', name: 'ECDSA' }, associationKeypairPrivateKey, publicKeyBuffer);
30
- const response = new Uint8Array(publicKeyBuffer.byteLength + signatureBuffer.byteLength);
31
- response.set(new Uint8Array(publicKeyBuffer), 0);
32
- response.set(new Uint8Array(signatureBuffer), publicKeyBuffer.byteLength);
33
- return response;
34
- });
35
- }
36
-
37
1
  class SolanaMobileWalletAdapterSecureContextRequiredError extends Error {
38
2
  constructor() {
39
3
  super('The mobile wallet adapter protocol must be used in a secure context (`https`).');
@@ -96,6 +60,42 @@ class SolanaMobileWalletAdapterProtocolJsonRpcError extends Error {
96
60
  }
97
61
  }
98
62
 
63
+ /******************************************************************************
64
+ Copyright (c) Microsoft Corporation.
65
+
66
+ Permission to use, copy, modify, and/or distribute this software for any
67
+ purpose with or without fee is hereby granted.
68
+
69
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
70
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
71
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
72
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
73
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
74
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
75
+ PERFORMANCE OF THIS SOFTWARE.
76
+ ***************************************************************************** */
77
+
78
+ function __awaiter(thisArg, _arguments, P, generator) {
79
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
80
+ return new (P || (P = Promise))(function (resolve, reject) {
81
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
82
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
83
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
84
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
85
+ });
86
+ }
87
+
88
+ function createHelloReq(ecdhPublicKey, associationKeypairPrivateKey) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ const publicKeyBuffer = yield crypto.subtle.exportKey('raw', ecdhPublicKey);
91
+ const signatureBuffer = yield crypto.subtle.sign({ hash: 'SHA-256', name: 'ECDSA' }, associationKeypairPrivateKey, publicKeyBuffer);
92
+ const response = new Uint8Array(publicKeyBuffer.byteLength + signatureBuffer.byteLength);
93
+ response.set(new Uint8Array(publicKeyBuffer), 0);
94
+ response.set(new Uint8Array(signatureBuffer), publicKeyBuffer.byteLength);
95
+ return response;
96
+ });
97
+ }
98
+
99
99
  function generateAssociationKeypair() {
100
100
  return __awaiter(this, void 0, void 0, function* () {
101
101
  return yield crypto.subtle.generateKey({
@@ -338,7 +338,7 @@ function assertSecureContext() {
338
338
  throw new SolanaMobileWalletAdapterSecureContextRequiredError();
339
339
  }
340
340
  }
341
- function withLocalWallet(callback, config) {
341
+ function transact(callback, config) {
342
342
  return __awaiter(this, void 0, void 0, function* () {
343
343
  assertSecureContext();
344
344
  const associationKeypair = yield generateAssociationKeypair();
@@ -412,7 +412,7 @@ function withLocalWallet(callback, config) {
412
412
  case 'hello_req_sent': {
413
413
  const sharedSecret = yield parseHelloRsp(responseBuffer, state.associationPublicKey, state.ecdhPrivateKey);
414
414
  state = { __type: 'connected', sharedSecret };
415
- const wallet = (method, params) => __awaiter(this, void 0, void 0, function* () {
415
+ const walletAPI = (method, params) => __awaiter(this, void 0, void 0, function* () {
416
416
  const id = nextJsonRpcMessageId++;
417
417
  socket.send(yield encryptJsonRpcMessage({
418
418
  id,
@@ -425,7 +425,7 @@ function withLocalWallet(callback, config) {
425
425
  });
426
426
  });
427
427
  try {
428
- resolve(yield callback(wallet));
428
+ resolve(yield callback(walletAPI));
429
429
  }
430
430
  catch (e) {
431
431
  reject(e);
@@ -463,4 +463,4 @@ function withLocalWallet(callback, config) {
463
463
  });
464
464
  }
465
465
 
466
- export { SolanaMobileWalletAdapterForbiddenWalletBaseURLError, SolanaMobileWalletAdapterProtocolAssociationPortOutOfRangeError, SolanaMobileWalletAdapterProtocolError, SolanaMobileWalletAdapterProtocolJsonRpcError, SolanaMobileWalletAdapterProtocolReauthorizeError, SolanaMobileWalletAdapterProtocolSessionClosedError, SolanaMobileWalletAdapterProtocolSessionEstablishmentError, SolanaMobileWalletAdapterSecureContextRequiredError, SolanaMobileWalletAdapterWalletNotInstalledError, withLocalWallet };
466
+ export { SolanaMobileWalletAdapterForbiddenWalletBaseURLError, SolanaMobileWalletAdapterProtocolAssociationPortOutOfRangeError, SolanaMobileWalletAdapterProtocolError, SolanaMobileWalletAdapterProtocolJsonRpcError, SolanaMobileWalletAdapterProtocolReauthorizeError, SolanaMobileWalletAdapterProtocolSessionClosedError, SolanaMobileWalletAdapterProtocolSessionEstablishmentError, SolanaMobileWalletAdapterSecureContextRequiredError, SolanaMobileWalletAdapterWalletNotInstalledError, transact };