@mysten/enoki 0.6.19 → 0.7.0
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/CHANGELOG.md +18 -0
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +8 -3
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/wallet/feature.d.ts +31 -0
- package/dist/cjs/wallet/feature.js +25 -0
- package/dist/cjs/wallet/feature.js.map +7 -0
- package/dist/cjs/wallet/index.d.ts +2 -2
- package/dist/cjs/wallet/index.js +24 -12
- package/dist/cjs/wallet/index.js.map +2 -2
- package/dist/cjs/wallet/state.d.ts +1 -1
- package/dist/cjs/wallet/state.js +1 -1
- package/dist/cjs/wallet/state.js.map +2 -2
- package/dist/cjs/wallet/utils.d.ts +9 -0
- package/dist/cjs/wallet/utils.js +65 -0
- package/dist/cjs/wallet/utils.js.map +7 -0
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +12 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/wallet/feature.d.ts +31 -0
- package/dist/esm/wallet/feature.js +5 -0
- package/dist/esm/wallet/feature.js.map +7 -0
- package/dist/esm/wallet/index.d.ts +2 -2
- package/dist/esm/wallet/index.js +34 -13
- package/dist/esm/wallet/index.js.map +2 -2
- package/dist/esm/wallet/state.d.ts +1 -1
- package/dist/esm/wallet/state.js +1 -1
- package/dist/esm/wallet/state.js.map +2 -2
- package/dist/esm/wallet/utils.d.ts +9 -0
- package/dist/esm/wallet/utils.js +45 -0
- package/dist/esm/wallet/utils.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mysten/enoki
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4117d38: Add methods for filtering and identifying Enoki wallets given `UiWallet` handles
|
|
8
|
+
- 5ef7cad: Return information about the active session from the new `EnokiGetMetadata` feature
|
|
9
|
+
- 81804c7: Revert small change that made `getWalletMetadata` throw an error instead of returning
|
|
10
|
+
null
|
|
11
|
+
|
|
12
|
+
## 0.6.20
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [a00522b]
|
|
17
|
+
- @mysten/sui@1.33.0
|
|
18
|
+
- @mysten/signers@0.2.17
|
|
19
|
+
- @mysten/wallet-standard@0.16.2
|
|
20
|
+
|
|
3
21
|
## 0.6.19
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { EnokiFlow, type EnokiFlowConfig } from './EnokiFlow.js';
|
|
|
4
4
|
export { createLocalStorage, createSessionStorage, createInMemoryStorage, type SyncStore, } from './stores.js';
|
|
5
5
|
export { createDefaultEncryption, type Encryption } from './encryption.js';
|
|
6
6
|
export { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';
|
|
7
|
-
export {
|
|
7
|
+
export { registerEnokiWallets, type EnokiWallet } from './wallet/index.js';
|
|
8
|
+
export { isEnokiWallet, isGoogleWallet, isTwitchWallet, isFacebookWallet, getWalletMetadata, } from './wallet/utils.js';
|
|
8
9
|
export { type RegisterEnokiWalletsOptions } from './wallet/types.js';
|
|
9
10
|
export { isEnokiNetwork } from './utils.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,8 +27,12 @@ __export(index_exports, {
|
|
|
27
27
|
createInMemoryStorage: () => import_stores.createInMemoryStorage,
|
|
28
28
|
createLocalStorage: () => import_stores.createLocalStorage,
|
|
29
29
|
createSessionStorage: () => import_stores.createSessionStorage,
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
getWalletMetadata: () => import_utils.getWalletMetadata,
|
|
31
|
+
isEnokiNetwork: () => import_utils2.isEnokiNetwork,
|
|
32
|
+
isEnokiWallet: () => import_utils.isEnokiWallet,
|
|
33
|
+
isFacebookWallet: () => import_utils.isFacebookWallet,
|
|
34
|
+
isGoogleWallet: () => import_utils.isGoogleWallet,
|
|
35
|
+
isTwitchWallet: () => import_utils.isTwitchWallet,
|
|
32
36
|
registerEnokiWallets: () => import_wallet.registerEnokiWallets
|
|
33
37
|
});
|
|
34
38
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -38,5 +42,6 @@ var import_stores = require("./stores.js");
|
|
|
38
42
|
var import_encryption = require("./encryption.js");
|
|
39
43
|
var import_EnokiKeypair = require("./EnokiKeypair.js");
|
|
40
44
|
var import_wallet = require("./wallet/index.js");
|
|
41
|
-
var import_utils = require("./utils.js");
|
|
45
|
+
var import_utils = require("./wallet/utils.js");
|
|
46
|
+
var import_utils2 = require("./utils.js");
|
|
42
47
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { EnokiClient, type EnokiClientConfig, EnokiClientError } from './EnokiClient/index.js';\nexport type { EnokiNetwork, AuthProvider } from './EnokiClient/type.js';\nexport { EnokiFlow, type EnokiFlowConfig } from './EnokiFlow.js';\nexport {\n\tcreateLocalStorage,\n\tcreateSessionStorage,\n\tcreateInMemoryStorage,\n\ttype SyncStore,\n} from './stores.js';\nexport { createDefaultEncryption, type Encryption } from './encryption.js';\nexport { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';\n\nexport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAsE;AAEtE,uBAAgD;AAChD,oBAKO;AACP,wBAAyD;AACzD,0BAA6C;AAE7C,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { EnokiClient, type EnokiClientConfig, EnokiClientError } from './EnokiClient/index.js';\nexport type { EnokiNetwork, AuthProvider } from './EnokiClient/type.js';\nexport { EnokiFlow, type EnokiFlowConfig } from './EnokiFlow.js';\nexport {\n\tcreateLocalStorage,\n\tcreateSessionStorage,\n\tcreateInMemoryStorage,\n\ttype SyncStore,\n} from './stores.js';\nexport { createDefaultEncryption, type Encryption } from './encryption.js';\nexport { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';\n\nexport { registerEnokiWallets, type EnokiWallet } from './wallet/index.js';\nexport {\n\tisEnokiWallet,\n\tisGoogleWallet,\n\tisTwitchWallet,\n\tisFacebookWallet,\n\tgetWalletMetadata,\n} from './wallet/utils.js';\nexport { type RegisterEnokiWalletsOptions } from './wallet/types.js';\n\nexport { isEnokiNetwork } from './utils.js';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAsE;AAEtE,uBAAgD;AAChD,oBAKO;AACP,wBAAyD;AACzD,0BAA6C;AAE7C,oBAAuD;AACvD,mBAMO;AAGP,IAAAA,gBAA+B;",
|
|
6
|
+
"names": ["import_utils"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { decodeJwt } from '@mysten/sui/zklogin';
|
|
2
|
+
import type { AuthProvider } from '../EnokiClient/type.js';
|
|
3
|
+
/** Name of the feature. */
|
|
4
|
+
export declare const EnokiGetMetadata = "enoki:getMetadata";
|
|
5
|
+
/** The latest API version of the getEnokiMetadata API. */
|
|
6
|
+
export type EnokiGetMetadataVersion = '1.0.0';
|
|
7
|
+
/**
|
|
8
|
+
* A Wallet Standard feature for retreiving Enoki-specific metadata about the wallet.
|
|
9
|
+
*/
|
|
10
|
+
export type EnokiGetMetadataFeature = {
|
|
11
|
+
/** Namespace for the feature. */
|
|
12
|
+
[EnokiGetMetadata]: {
|
|
13
|
+
/** Version of the feature API. */
|
|
14
|
+
version: '1.0.0';
|
|
15
|
+
getMetadata: EnokiGetMetadataMethod;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type EnokiGetMetadataMethod = (input?: EnokiGetMetadataInput) => EnokiGetMetadataOutput;
|
|
19
|
+
/** Input for retrieving metadata about the wallet. */
|
|
20
|
+
export interface EnokiGetMetadataInput {
|
|
21
|
+
}
|
|
22
|
+
/** Output of retrieving metadata about the wallet. */
|
|
23
|
+
export interface EnokiGetMetadataOutput {
|
|
24
|
+
/** The social provider for the wallet. */
|
|
25
|
+
provider: AuthProvider;
|
|
26
|
+
/** Metadata pertaining to the active session. */
|
|
27
|
+
activeSession?: {
|
|
28
|
+
/** The decoded JWT for the session. */
|
|
29
|
+
decodedJwt: ReturnType<typeof decodeJwt>;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var feature_exports = {};
|
|
20
|
+
__export(feature_exports, {
|
|
21
|
+
EnokiGetMetadata: () => EnokiGetMetadata
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(feature_exports);
|
|
24
|
+
const EnokiGetMetadata = "enoki:getMetadata";
|
|
25
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/wallet/feature.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { decodeJwt } from '@mysten/sui/zklogin';\nimport type { AuthProvider } from '../EnokiClient/type.js';\n\n/** Name of the feature. */\nexport const EnokiGetMetadata = 'enoki:getMetadata';\n\n/** The latest API version of the getEnokiMetadata API. */\nexport type EnokiGetMetadataVersion = '1.0.0';\n\n/**\n * A Wallet Standard feature for retreiving Enoki-specific metadata about the wallet.\n */\nexport type EnokiGetMetadataFeature = {\n\t/** Namespace for the feature. */\n\t[EnokiGetMetadata]: {\n\t\t/** Version of the feature API. */\n\t\tversion: '1.0.0';\n\t\tgetMetadata: EnokiGetMetadataMethod;\n\t};\n};\n\nexport type EnokiGetMetadataMethod = (input?: EnokiGetMetadataInput) => EnokiGetMetadataOutput;\n\n/** Input for retrieving metadata about the wallet. */\nexport interface EnokiGetMetadataInput {}\n\n/** Output of retrieving metadata about the wallet. */\nexport interface EnokiGetMetadataOutput {\n\t/** The social provider for the wallet. */\n\tprovider: AuthProvider;\n\n\t/** Metadata pertaining to the active session. */\n\tactiveSession?: {\n\t\t/** The decoded JWT for the session. */\n\t\tdecodedJwt: ReturnType<typeof decodeJwt>;\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,MAAM,mBAAmB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -4,6 +4,7 @@ import { ReadonlyWalletAccount } from '@mysten/wallet-standard';
|
|
|
4
4
|
import type { AuthProvider } from '../EnokiClient/type.js';
|
|
5
5
|
import { INTERNAL_ONLY_EnokiFlow } from './state.js';
|
|
6
6
|
import type { RegisterEnokiWalletsOptions } from './types.js';
|
|
7
|
+
import type { EnokiGetMetadataFeature } from './feature.js';
|
|
7
8
|
export declare class EnokiWallet implements Wallet {
|
|
8
9
|
#private;
|
|
9
10
|
get id(): string;
|
|
@@ -13,7 +14,7 @@ export declare class EnokiWallet implements Wallet {
|
|
|
13
14
|
get version(): "1.0.0";
|
|
14
15
|
get chains(): readonly ["sui:mainnet" | "sui:testnet" | "sui:devnet"];
|
|
15
16
|
get accounts(): ReadonlyWalletAccount[];
|
|
16
|
-
get features(): StandardConnectFeature & StandardDisconnectFeature & StandardEventsFeature & SuiSignTransactionFeature & SuiSignAndExecuteTransactionFeature & SuiSignPersonalMessageFeature;
|
|
17
|
+
get features(): StandardConnectFeature & StandardDisconnectFeature & StandardEventsFeature & SuiSignTransactionFeature & SuiSignAndExecuteTransactionFeature & SuiSignPersonalMessageFeature & EnokiGetMetadataFeature;
|
|
17
18
|
constructor({ name, icon, flow, provider, clientId, redirectUrl, extraParams, client, windowFeatures, }: {
|
|
18
19
|
icon: Wallet['icon'];
|
|
19
20
|
name: string;
|
|
@@ -30,5 +31,4 @@ export declare function registerEnokiWallets({ providers, client, network, windo
|
|
|
30
31
|
wallets: Partial<Record<AuthProvider, EnokiWallet>>;
|
|
31
32
|
unregister: () => void;
|
|
32
33
|
};
|
|
33
|
-
export declare function isEnokiWallet(wallet: Wallet): wallet is EnokiWallet;
|
|
34
34
|
export declare function defaultWindowFeatures(): string;
|
package/dist/cjs/wallet/index.js
CHANGED
|
@@ -38,7 +38,6 @@ var wallet_exports = {};
|
|
|
38
38
|
__export(wallet_exports, {
|
|
39
39
|
EnokiWallet: () => EnokiWallet,
|
|
40
40
|
defaultWindowFeatures: () => defaultWindowFeatures,
|
|
41
|
-
isEnokiWallet: () => isEnokiWallet,
|
|
42
41
|
registerEnokiWallets: () => registerEnokiWallets
|
|
43
42
|
});
|
|
44
43
|
module.exports = __toCommonJS(wallet_exports);
|
|
@@ -48,7 +47,9 @@ var import_wallet_standard = require("@mysten/wallet-standard");
|
|
|
48
47
|
var import_mitt = __toESM(require("mitt"));
|
|
49
48
|
var import_providers = require("./providers.js");
|
|
50
49
|
var import_state = require("./state.js");
|
|
51
|
-
var
|
|
50
|
+
var import_feature = require("./feature.js");
|
|
51
|
+
var import_zklogin = require("@mysten/sui/zklogin");
|
|
52
|
+
var _events, _accounts, _name, _id, _icon, _flow, _provider, _clientId, _redirectUrl, _extraParams, _client, _windowFeatures, _signTransaction, _signAndExecuteTransaction, _signPersonalMessage, _on, _EnokiWallet_instances, setAccount_fn, _connect, _getMetadata, _disconnect, validateChain_fn;
|
|
52
53
|
class EnokiWallet {
|
|
53
54
|
constructor({
|
|
54
55
|
name,
|
|
@@ -167,6 +168,14 @@ class EnokiWallet {
|
|
|
167
168
|
__privateMethod(this, _EnokiWallet_instances, setAccount_fn).call(this);
|
|
168
169
|
return { accounts: this.accounts };
|
|
169
170
|
});
|
|
171
|
+
__privateAdd(this, _getMetadata, () => {
|
|
172
|
+
const session = __privateGet(this, _flow).$zkLoginSession.get();
|
|
173
|
+
const decodedJwt = session.value?.jwt ? (0, import_zklogin.decodeJwt)(session.value.jwt) : void 0;
|
|
174
|
+
return {
|
|
175
|
+
provider: __privateGet(this, _provider),
|
|
176
|
+
activeSession: decodedJwt ? { decodedJwt } : void 0
|
|
177
|
+
};
|
|
178
|
+
});
|
|
170
179
|
__privateAdd(this, _disconnect, async () => {
|
|
171
180
|
await __privateGet(this, _flow).logout();
|
|
172
181
|
__privateMethod(this, _EnokiWallet_instances, setAccount_fn).call(this);
|
|
@@ -208,29 +217,33 @@ class EnokiWallet {
|
|
|
208
217
|
}
|
|
209
218
|
get features() {
|
|
210
219
|
return {
|
|
211
|
-
|
|
220
|
+
[import_wallet_standard.StandardConnect]: {
|
|
212
221
|
version: "1.0.0",
|
|
213
222
|
connect: __privateGet(this, _connect)
|
|
214
223
|
},
|
|
215
|
-
|
|
224
|
+
[import_wallet_standard.StandardDisconnect]: {
|
|
216
225
|
version: "1.0.0",
|
|
217
226
|
disconnect: __privateGet(this, _disconnect)
|
|
218
227
|
},
|
|
219
|
-
|
|
228
|
+
[import_wallet_standard.StandardEvents]: {
|
|
220
229
|
version: "1.0.0",
|
|
221
230
|
on: __privateGet(this, _on)
|
|
222
231
|
},
|
|
223
|
-
|
|
232
|
+
[import_wallet_standard.SuiSignTransaction]: {
|
|
224
233
|
version: "2.0.0",
|
|
225
234
|
signTransaction: __privateGet(this, _signTransaction)
|
|
226
235
|
},
|
|
227
|
-
|
|
236
|
+
[import_wallet_standard.SuiSignAndExecuteTransaction]: {
|
|
228
237
|
version: "2.0.0",
|
|
229
238
|
signAndExecuteTransaction: __privateGet(this, _signAndExecuteTransaction)
|
|
230
239
|
},
|
|
231
|
-
|
|
240
|
+
[import_wallet_standard.SuiSignPersonalMessage]: {
|
|
232
241
|
version: "1.1.0",
|
|
233
242
|
signPersonalMessage: __privateGet(this, _signPersonalMessage)
|
|
243
|
+
},
|
|
244
|
+
[import_feature.EnokiGetMetadata]: {
|
|
245
|
+
version: "1.0.0",
|
|
246
|
+
getMetadata: __privateGet(this, _getMetadata)
|
|
234
247
|
}
|
|
235
248
|
};
|
|
236
249
|
}
|
|
@@ -259,7 +272,8 @@ setAccount_fn = function() {
|
|
|
259
272
|
new import_wallet_standard.ReadonlyWalletAccount({
|
|
260
273
|
address: state.address,
|
|
261
274
|
chains: this.chains,
|
|
262
|
-
|
|
275
|
+
icon: this.icon,
|
|
276
|
+
features: [import_wallet_standard.SuiSignPersonalMessage, import_wallet_standard.SuiSignTransaction, import_wallet_standard.SuiSignAndExecuteTransaction],
|
|
263
277
|
publicKey: (0, import_utils.fromBase64)(state.publicKey)
|
|
264
278
|
})
|
|
265
279
|
]);
|
|
@@ -269,6 +283,7 @@ setAccount_fn = function() {
|
|
|
269
283
|
__privateGet(this, _events).emit("change", { accounts: this.accounts });
|
|
270
284
|
};
|
|
271
285
|
_connect = new WeakMap();
|
|
286
|
+
_getMetadata = new WeakMap();
|
|
272
287
|
_disconnect = new WeakMap();
|
|
273
288
|
validateChain_fn = function(chain) {
|
|
274
289
|
if (!chain || !this.chains.includes(chain)) {
|
|
@@ -317,9 +332,6 @@ function registerEnokiWallets({
|
|
|
317
332
|
}
|
|
318
333
|
};
|
|
319
334
|
}
|
|
320
|
-
function isEnokiWallet(wallet) {
|
|
321
|
-
return !!wallet.id?.startsWith("enoki:");
|
|
322
|
-
}
|
|
323
335
|
function defaultWindowFeatures() {
|
|
324
336
|
const width = 500;
|
|
325
337
|
const height = 800;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/wallet/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiClient } from '@mysten/sui/client';\nimport { Transaction } from '@mysten/sui/transactions';\nimport { fromBase64, toBase64 } from '@mysten/sui/utils';\nimport type {\n\tIdentifierArray,\n\tIdentifierString,\n\tStandardConnectFeature,\n\tStandardConnectMethod,\n\tStandardDisconnectFeature,\n\tStandardDisconnectMethod,\n\tStandardEventsFeature,\n\tStandardEventsOnMethod,\n\tSuiSignAndExecuteTransactionFeature,\n\tSuiSignAndExecuteTransactionMethod,\n\tSuiSignPersonalMessageFeature,\n\tSuiSignPersonalMessageMethod,\n\tSuiSignTransactionFeature,\n\tSuiSignTransactionMethod,\n\tWallet,\n} from '@mysten/wallet-standard';\nimport { getWallets, ReadonlyWalletAccount } from '@mysten/wallet-standard';\nimport type { Emitter } from 'mitt';\nimport mitt from 'mitt';\n\nimport type { AuthProvider } from '../EnokiClient/type.js';\nimport { ENOKI_PROVIDER_WALLETS_INFO } from './providers.js';\nimport { INTERNAL_ONLY_EnokiFlow } from './state.js';\nimport type { RegisterEnokiWalletsOptions, WalletEventsMap } from './types.js';\n\nexport class EnokiWallet implements Wallet {\n\t#events: Emitter<WalletEventsMap>;\n\t#accounts: ReadonlyWalletAccount[];\n\t#name: string;\n\t#id: string;\n\t#icon: Wallet['icon'];\n\t#flow: INTERNAL_ONLY_EnokiFlow;\n\t#provider: AuthProvider;\n\t#clientId: string;\n\t#redirectUrl: string | undefined;\n\t#extraParams: Record<string, string> | undefined;\n\t#client;\n\t#windowFeatures?: string | (() => string);\n\n\tget id() {\n\t\treturn this.#id;\n\t}\n\n\tget name() {\n\t\treturn this.#name;\n\t}\n\n\tget provider() {\n\t\treturn this.#provider;\n\t}\n\n\tget icon() {\n\t\treturn this.#icon;\n\t}\n\n\tget version() {\n\t\treturn '1.0.0' as const;\n\t}\n\n\tget chains() {\n\t\treturn [`sui:${this.#flow.network}`] as const;\n\t}\n\n\tget accounts() {\n\t\treturn this.#accounts;\n\t}\n\n\tget features(): StandardConnectFeature &\n\t\tStandardDisconnectFeature &\n\t\tStandardEventsFeature &\n\t\tSuiSignTransactionFeature &\n\t\tSuiSignAndExecuteTransactionFeature &\n\t\tSuiSignPersonalMessageFeature {\n\t\treturn {\n\t\t\t'standard:connect': {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tconnect: this.#connect,\n\t\t\t},\n\t\t\t'standard:disconnect': {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tdisconnect: this.#disconnect,\n\t\t\t},\n\t\t\t'standard:events': {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\ton: this.#on,\n\t\t\t},\n\t\t\t'sui:signTransaction': {\n\t\t\t\tversion: '2.0.0',\n\t\t\t\tsignTransaction: this.#signTransaction,\n\t\t\t},\n\t\t\t'sui:signAndExecuteTransaction': {\n\t\t\t\tversion: '2.0.0',\n\t\t\t\tsignAndExecuteTransaction: this.#signAndExecuteTransaction,\n\t\t\t},\n\t\t\t'sui:signPersonalMessage': {\n\t\t\t\tversion: '1.1.0',\n\t\t\t\tsignPersonalMessage: this.#signPersonalMessage,\n\t\t\t},\n\t\t};\n\t}\n\n\tconstructor({\n\t\tname,\n\t\ticon,\n\t\tflow,\n\t\tprovider,\n\t\tclientId,\n\t\tredirectUrl,\n\t\textraParams,\n\t\tclient,\n\t\twindowFeatures,\n\t}: {\n\t\ticon: Wallet['icon'];\n\t\tname: string;\n\t\tflow: INTERNAL_ONLY_EnokiFlow;\n\t\tprovider: AuthProvider;\n\t\tclientId: string;\n\t\tredirectUrl?: string;\n\t\textraParams?: Record<string, string>;\n\t\tclient: SuiClient;\n\t\twindowFeatures?: string | (() => string);\n\t}) {\n\t\tthis.#accounts = [];\n\t\tthis.#events = mitt();\n\n\t\tthis.#client = client;\n\t\tthis.#name = name;\n\t\tthis.#id = `enoki:${provider}:${flow.network}:${clientId}`;\n\t\tthis.#icon = icon;\n\t\tthis.#flow = flow;\n\t\tthis.#provider = provider;\n\t\tthis.#clientId = clientId;\n\t\tthis.#redirectUrl = redirectUrl;\n\t\tthis.#extraParams = extraParams;\n\t\tthis.#windowFeatures = windowFeatures;\n\n\t\tthis.#setAccount();\n\t}\n\n\t#signTransaction: SuiSignTransactionMethod = async ({ transaction, chain, account }) => {\n\t\tthis.#validateChain(chain);\n\n\t\tconst parsedTransaction = Transaction.from(await transaction.toJSON());\n\t\tconst keypair = await this.#flow.getKeypair();\n\t\tconst suiAddress = keypair.toSuiAddress();\n\n\t\tif (suiAddress !== account.address) {\n\t\t\tthrow new Error(\n\t\t\t\t`The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`,\n\t\t\t);\n\t\t}\n\n\t\tparsedTransaction.setSenderIfNotSet(suiAddress);\n\t\treturn keypair.signTransaction(await parsedTransaction.build({ client: this.#client }));\n\t};\n\n\t#signAndExecuteTransaction: SuiSignAndExecuteTransactionMethod = async ({\n\t\ttransaction,\n\t\tchain,\n\t\taccount,\n\t}) => {\n\t\tconst { signature, bytes } = await this.#signTransaction({ transaction, account, chain });\n\t\tconst { digest, rawEffects } = await this.#client.executeTransactionBlock({\n\t\t\ttransactionBlock: bytes,\n\t\t\tsignature,\n\t\t\toptions: {\n\t\t\t\tshowRawEffects: true,\n\t\t\t},\n\t\t});\n\n\t\treturn {\n\t\t\tdigest,\n\t\t\tsignature,\n\t\t\tbytes,\n\t\t\teffects: toBase64(Uint8Array.from(rawEffects!)),\n\t\t};\n\t};\n\n\t#signPersonalMessage: SuiSignPersonalMessageMethod = async ({ message, account, chain }) => {\n\t\tthis.#validateChain(chain);\n\n\t\tconst keypair = await this.#flow.getKeypair();\n\t\tconst suiAddress = keypair.toSuiAddress();\n\n\t\tif (suiAddress !== account.address) {\n\t\t\tthrow new Error(\n\t\t\t\t`The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`,\n\t\t\t);\n\t\t}\n\n\t\treturn keypair.signPersonalMessage(message);\n\t};\n\n\t#on: StandardEventsOnMethod = (event, listener) => {\n\t\tthis.#events.on(event, listener);\n\t\treturn () => this.#events.off(event, listener);\n\t};\n\n\t#setAccount() {\n\t\tconst state = this.#flow.$zkLoginState.get();\n\t\tif (state.address && state.publicKey) {\n\t\t\tthis.#accounts = [\n\t\t\t\tnew ReadonlyWalletAccount({\n\t\t\t\t\taddress: state.address,\n\t\t\t\t\tchains: this.chains,\n\t\t\t\t\tfeatures: Object.keys(this.features) as IdentifierArray,\n\t\t\t\t\tpublicKey: fromBase64(state.publicKey),\n\t\t\t\t}),\n\t\t\t];\n\t\t} else {\n\t\t\tthis.#accounts = [];\n\t\t}\n\n\t\tthis.#events.emit('change', { accounts: this.accounts });\n\t}\n\n\t#connect: StandardConnectMethod = async (input) => {\n\t\tthis.#setAccount();\n\n\t\tif (this.accounts.length || input?.silent) {\n\t\t\treturn { accounts: this.accounts };\n\t\t}\n\n\t\tconst popup = window.open(\n\t\t\tundefined,\n\t\t\t'_blank',\n\t\t\ttypeof this.#windowFeatures === 'function' ? this.#windowFeatures() : this.#windowFeatures,\n\t\t);\n\t\tif (!popup) {\n\t\t\tthrow new Error('Failed to open popup');\n\t\t}\n\n\t\tconst url = await this.#flow.createAuthorizationURL({\n\t\t\tprovider: this.#provider,\n\t\t\tclientId: this.#clientId,\n\t\t\tredirectUrl: this.#redirectUrl ?? window.location.href.split('#')[0],\n\t\t\textraParams: this.#extraParams,\n\t\t});\n\n\t\tpopup.location = url;\n\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tconst interval = setInterval(() => {\n\t\t\t\ttry {\n\t\t\t\t\tif (popup.closed) {\n\t\t\t\t\t\tclearInterval(interval);\n\t\t\t\t\t\treject(new Error('Popup closed'));\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!popup.location.hash) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tclearInterval(interval);\n\n\t\t\t\tthis.#flow.handleAuthCallback(popup.location.hash).then(() => resolve(), reject);\n\n\t\t\t\ttry {\n\t\t\t\t\tpopup.close();\n\t\t\t\t} catch (e) {\n\t\t\t\t\tconsole.error(e);\n\t\t\t\t}\n\t\t\t}, 16);\n\t\t});\n\n\t\tthis.#setAccount();\n\n\t\treturn { accounts: this.accounts };\n\t};\n\n\t#disconnect: StandardDisconnectMethod = async () => {\n\t\tawait this.#flow.logout();\n\n\t\tthis.#setAccount();\n\t};\n\n\t#validateChain(chain?: IdentifierString): asserts chain is (typeof this.chains)[number] {\n\t\tif (!chain || !this.chains.includes(chain as (typeof this.chains)[number])) {\n\t\t\tthrow new Error(\n\t\t\t\t`A valid Sui chain identifier was not provided in the request. Please report this issue to the dApp developer. Examples of valid Sui chain identifiers are 'sui:testnet' and 'sui:mainnet'. Consider using the '@mysten/dapp-kit' package, which provides this value automatically.`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport function registerEnokiWallets({\n\tproviders,\n\tclient,\n\tnetwork = 'mainnet',\n\twindowFeatures = defaultWindowFeatures,\n\t...config\n}: RegisterEnokiWalletsOptions) {\n\tconst walletsApi = getWallets();\n\tconst flow = new INTERNAL_ONLY_EnokiFlow({ ...config, network });\n\n\tconst unregisterCallbacks: (() => void)[] = [];\n\tconst wallets: Partial<Record<AuthProvider, EnokiWallet>> = {};\n\n\tfor (const { name, icon, provider } of ENOKI_PROVIDER_WALLETS_INFO) {\n\t\tconst providerOptions = providers[provider];\n\t\tif (providerOptions) {\n\t\t\tconst { clientId, redirectUrl, extraParams } = providerOptions;\n\t\t\tconst wallet = new EnokiWallet({\n\t\t\t\tname,\n\t\t\t\ticon,\n\t\t\t\tflow,\n\t\t\t\tprovider,\n\t\t\t\tclientId,\n\t\t\t\tclient,\n\t\t\t\tredirectUrl,\n\t\t\t\textraParams,\n\t\t\t\twindowFeatures,\n\t\t\t});\n\n\t\t\tconst unregister = walletsApi.register(wallet);\n\t\t\tunregisterCallbacks.push(unregister);\n\n\t\t\twallets[provider] = wallet;\n\t\t}\n\t}\n\n\treturn {\n\t\twallets,\n\t\tunregister: () => {\n\t\t\tfor (const unregister of unregisterCallbacks) {\n\t\t\t\tunregister();\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport function isEnokiWallet(wallet: Wallet): wallet is EnokiWallet {\n\treturn !!wallet.id?.startsWith('enoki:');\n}\n\nexport function defaultWindowFeatures() {\n\tconst width = 500;\n\tconst height = 800;\n\tconst left = (screen.width - width) / 2;\n\tconst top = (screen.height - height) / 4;\n\n\treturn `popup=1;toolbar=0;status=0;resizable=1,width=${width},height=${height},top=${top},left=${left}`;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiClient } from '@mysten/sui/client';\nimport { Transaction } from '@mysten/sui/transactions';\nimport { fromBase64, toBase64 } from '@mysten/sui/utils';\nimport type {\n\tIdentifierString,\n\tStandardConnectFeature,\n\tStandardConnectMethod,\n\tStandardDisconnectFeature,\n\tStandardDisconnectMethod,\n\tStandardEventsFeature,\n\tStandardEventsOnMethod,\n\tSuiSignAndExecuteTransactionFeature,\n\tSuiSignAndExecuteTransactionMethod,\n\tSuiSignPersonalMessageFeature,\n\tSuiSignPersonalMessageMethod,\n\tSuiSignTransactionFeature,\n\tSuiSignTransactionMethod,\n\tWallet,\n} from '@mysten/wallet-standard';\nimport {\n\tgetWallets,\n\tReadonlyWalletAccount,\n\tStandardConnect,\n\tStandardDisconnect,\n\tStandardEvents,\n\tSuiSignAndExecuteTransaction,\n\tSuiSignPersonalMessage,\n\tSuiSignTransaction,\n} from '@mysten/wallet-standard';\nimport type { Emitter } from 'mitt';\nimport mitt from 'mitt';\n\nimport type { AuthProvider } from '../EnokiClient/type.js';\nimport { ENOKI_PROVIDER_WALLETS_INFO } from './providers.js';\nimport { INTERNAL_ONLY_EnokiFlow } from './state.js';\nimport type { RegisterEnokiWalletsOptions, WalletEventsMap } from './types.js';\nimport type { EnokiGetMetadataFeature, EnokiGetMetadataMethod } from './feature.js';\nimport { EnokiGetMetadata } from './feature.js';\nimport { decodeJwt } from '@mysten/sui/zklogin';\n\nexport class EnokiWallet implements Wallet {\n\t#events: Emitter<WalletEventsMap>;\n\t#accounts: ReadonlyWalletAccount[];\n\t#name: string;\n\t#id: string;\n\t#icon: Wallet['icon'];\n\t#flow: INTERNAL_ONLY_EnokiFlow;\n\t#provider: AuthProvider;\n\t#clientId: string;\n\t#redirectUrl: string | undefined;\n\t#extraParams: Record<string, string> | undefined;\n\t#client;\n\t#windowFeatures?: string | (() => string);\n\n\tget id() {\n\t\treturn this.#id;\n\t}\n\n\tget name() {\n\t\treturn this.#name;\n\t}\n\n\tget provider() {\n\t\treturn this.#provider;\n\t}\n\n\tget icon() {\n\t\treturn this.#icon;\n\t}\n\n\tget version() {\n\t\treturn '1.0.0' as const;\n\t}\n\n\tget chains() {\n\t\treturn [`sui:${this.#flow.network}`] as const;\n\t}\n\n\tget accounts() {\n\t\treturn this.#accounts;\n\t}\n\n\tget features(): StandardConnectFeature &\n\t\tStandardDisconnectFeature &\n\t\tStandardEventsFeature &\n\t\tSuiSignTransactionFeature &\n\t\tSuiSignAndExecuteTransactionFeature &\n\t\tSuiSignPersonalMessageFeature &\n\t\tEnokiGetMetadataFeature {\n\t\treturn {\n\t\t\t[StandardConnect]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tconnect: this.#connect,\n\t\t\t},\n\t\t\t[StandardDisconnect]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tdisconnect: this.#disconnect,\n\t\t\t},\n\t\t\t[StandardEvents]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\ton: this.#on,\n\t\t\t},\n\t\t\t[SuiSignTransaction]: {\n\t\t\t\tversion: '2.0.0',\n\t\t\t\tsignTransaction: this.#signTransaction,\n\t\t\t},\n\t\t\t[SuiSignAndExecuteTransaction]: {\n\t\t\t\tversion: '2.0.0',\n\t\t\t\tsignAndExecuteTransaction: this.#signAndExecuteTransaction,\n\t\t\t},\n\t\t\t[SuiSignPersonalMessage]: {\n\t\t\t\tversion: '1.1.0',\n\t\t\t\tsignPersonalMessage: this.#signPersonalMessage,\n\t\t\t},\n\t\t\t[EnokiGetMetadata]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tgetMetadata: this.#getMetadata,\n\t\t\t},\n\t\t};\n\t}\n\n\tconstructor({\n\t\tname,\n\t\ticon,\n\t\tflow,\n\t\tprovider,\n\t\tclientId,\n\t\tredirectUrl,\n\t\textraParams,\n\t\tclient,\n\t\twindowFeatures,\n\t}: {\n\t\ticon: Wallet['icon'];\n\t\tname: string;\n\t\tflow: INTERNAL_ONLY_EnokiFlow;\n\t\tprovider: AuthProvider;\n\t\tclientId: string;\n\t\tredirectUrl?: string;\n\t\textraParams?: Record<string, string>;\n\t\tclient: SuiClient;\n\t\twindowFeatures?: string | (() => string);\n\t}) {\n\t\tthis.#accounts = [];\n\t\tthis.#events = mitt();\n\n\t\tthis.#client = client;\n\t\tthis.#name = name;\n\t\tthis.#id = `enoki:${provider}:${flow.network}:${clientId}`;\n\t\tthis.#icon = icon;\n\t\tthis.#flow = flow;\n\t\tthis.#provider = provider;\n\t\tthis.#clientId = clientId;\n\t\tthis.#redirectUrl = redirectUrl;\n\t\tthis.#extraParams = extraParams;\n\t\tthis.#windowFeatures = windowFeatures;\n\n\t\tthis.#setAccount();\n\t}\n\n\t#signTransaction: SuiSignTransactionMethod = async ({ transaction, chain, account }) => {\n\t\tthis.#validateChain(chain);\n\n\t\tconst parsedTransaction = Transaction.from(await transaction.toJSON());\n\t\tconst keypair = await this.#flow.getKeypair();\n\t\tconst suiAddress = keypair.toSuiAddress();\n\n\t\tif (suiAddress !== account.address) {\n\t\t\tthrow new Error(\n\t\t\t\t`The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`,\n\t\t\t);\n\t\t}\n\n\t\tparsedTransaction.setSenderIfNotSet(suiAddress);\n\t\treturn keypair.signTransaction(await parsedTransaction.build({ client: this.#client }));\n\t};\n\n\t#signAndExecuteTransaction: SuiSignAndExecuteTransactionMethod = async ({\n\t\ttransaction,\n\t\tchain,\n\t\taccount,\n\t}) => {\n\t\tconst { signature, bytes } = await this.#signTransaction({ transaction, account, chain });\n\t\tconst { digest, rawEffects } = await this.#client.executeTransactionBlock({\n\t\t\ttransactionBlock: bytes,\n\t\t\tsignature,\n\t\t\toptions: {\n\t\t\t\tshowRawEffects: true,\n\t\t\t},\n\t\t});\n\n\t\treturn {\n\t\t\tdigest,\n\t\t\tsignature,\n\t\t\tbytes,\n\t\t\teffects: toBase64(Uint8Array.from(rawEffects!)),\n\t\t};\n\t};\n\n\t#signPersonalMessage: SuiSignPersonalMessageMethod = async ({ message, account, chain }) => {\n\t\tthis.#validateChain(chain);\n\n\t\tconst keypair = await this.#flow.getKeypair();\n\t\tconst suiAddress = keypair.toSuiAddress();\n\n\t\tif (suiAddress !== account.address) {\n\t\t\tthrow new Error(\n\t\t\t\t`The specified account ${account.address} does not match the currently connected Enoki address ${suiAddress}.`,\n\t\t\t);\n\t\t}\n\n\t\treturn keypair.signPersonalMessage(message);\n\t};\n\n\t#on: StandardEventsOnMethod = (event, listener) => {\n\t\tthis.#events.on(event, listener);\n\t\treturn () => this.#events.off(event, listener);\n\t};\n\n\t#setAccount() {\n\t\tconst state = this.#flow.$zkLoginState.get();\n\t\tif (state.address && state.publicKey) {\n\t\t\tthis.#accounts = [\n\t\t\t\tnew ReadonlyWalletAccount({\n\t\t\t\t\taddress: state.address,\n\t\t\t\t\tchains: this.chains,\n\t\t\t\t\ticon: this.icon,\n\t\t\t\t\tfeatures: [SuiSignPersonalMessage, SuiSignTransaction, SuiSignAndExecuteTransaction],\n\t\t\t\t\tpublicKey: fromBase64(state.publicKey),\n\t\t\t\t}),\n\t\t\t];\n\t\t} else {\n\t\t\tthis.#accounts = [];\n\t\t}\n\n\t\tthis.#events.emit('change', { accounts: this.accounts });\n\t}\n\n\t#connect: StandardConnectMethod = async (input) => {\n\t\tthis.#setAccount();\n\n\t\tif (this.accounts.length || input?.silent) {\n\t\t\treturn { accounts: this.accounts };\n\t\t}\n\n\t\tconst popup = window.open(\n\t\t\tundefined,\n\t\t\t'_blank',\n\t\t\ttypeof this.#windowFeatures === 'function' ? this.#windowFeatures() : this.#windowFeatures,\n\t\t);\n\t\tif (!popup) {\n\t\t\tthrow new Error('Failed to open popup');\n\t\t}\n\n\t\tconst url = await this.#flow.createAuthorizationURL({\n\t\t\tprovider: this.#provider,\n\t\t\tclientId: this.#clientId,\n\t\t\tredirectUrl: this.#redirectUrl ?? window.location.href.split('#')[0],\n\t\t\textraParams: this.#extraParams,\n\t\t});\n\n\t\tpopup.location = url;\n\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tconst interval = setInterval(() => {\n\t\t\t\ttry {\n\t\t\t\t\tif (popup.closed) {\n\t\t\t\t\t\tclearInterval(interval);\n\t\t\t\t\t\treject(new Error('Popup closed'));\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!popup.location.hash) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tclearInterval(interval);\n\n\t\t\t\tthis.#flow.handleAuthCallback(popup.location.hash).then(() => resolve(), reject);\n\n\t\t\t\ttry {\n\t\t\t\t\tpopup.close();\n\t\t\t\t} catch (e) {\n\t\t\t\t\tconsole.error(e);\n\t\t\t\t}\n\t\t\t}, 16);\n\t\t});\n\n\t\tthis.#setAccount();\n\n\t\treturn { accounts: this.accounts };\n\t};\n\n\t#getMetadata: EnokiGetMetadataMethod = () => {\n\t\tconst session = this.#flow.$zkLoginSession.get();\n\t\tconst decodedJwt = session.value?.jwt ? decodeJwt(session.value.jwt) : undefined;\n\n\t\treturn {\n\t\t\tprovider: this.#provider,\n\t\t\tactiveSession: decodedJwt ? { decodedJwt } : undefined,\n\t\t};\n\t};\n\n\t#disconnect: StandardDisconnectMethod = async () => {\n\t\tawait this.#flow.logout();\n\n\t\tthis.#setAccount();\n\t};\n\n\t#validateChain(chain?: IdentifierString): asserts chain is (typeof this.chains)[number] {\n\t\tif (!chain || !this.chains.includes(chain as (typeof this.chains)[number])) {\n\t\t\tthrow new Error(\n\t\t\t\t`A valid Sui chain identifier was not provided in the request. Please report this issue to the dApp developer. Examples of valid Sui chain identifiers are 'sui:testnet' and 'sui:mainnet'. Consider using the '@mysten/dapp-kit' package, which provides this value automatically.`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport function registerEnokiWallets({\n\tproviders,\n\tclient,\n\tnetwork = 'mainnet',\n\twindowFeatures = defaultWindowFeatures,\n\t...config\n}: RegisterEnokiWalletsOptions) {\n\tconst walletsApi = getWallets();\n\tconst flow = new INTERNAL_ONLY_EnokiFlow({ ...config, network });\n\n\tconst unregisterCallbacks: (() => void)[] = [];\n\tconst wallets: Partial<Record<AuthProvider, EnokiWallet>> = {};\n\n\tfor (const { name, icon, provider } of ENOKI_PROVIDER_WALLETS_INFO) {\n\t\tconst providerOptions = providers[provider];\n\t\tif (providerOptions) {\n\t\t\tconst { clientId, redirectUrl, extraParams } = providerOptions;\n\t\t\tconst wallet = new EnokiWallet({\n\t\t\t\tname,\n\t\t\t\ticon,\n\t\t\t\tflow,\n\t\t\t\tprovider,\n\t\t\t\tclientId,\n\t\t\t\tclient,\n\t\t\t\tredirectUrl,\n\t\t\t\textraParams,\n\t\t\t\twindowFeatures,\n\t\t\t});\n\n\t\t\tconst unregister = walletsApi.register(wallet);\n\t\t\tunregisterCallbacks.push(unregister);\n\n\t\t\twallets[provider] = wallet;\n\t\t}\n\t}\n\n\treturn {\n\t\twallets,\n\t\tunregister: () => {\n\t\t\tfor (const unregister of unregisterCallbacks) {\n\t\t\t\tunregister();\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport function defaultWindowFeatures() {\n\tconst width = 500;\n\tconst height = 800;\n\tconst left = (screen.width - width) / 2;\n\tconst top = (screen.height - height) / 4;\n\n\treturn `popup=1;toolbar=0;status=0;resizable=1,width=${width},height=${height},top=${top},left=${left}`;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,0BAA4B;AAC5B,mBAAqC;AAiBrC,6BASO;AAEP,kBAAiB;AAGjB,uBAA4C;AAC5C,mBAAwC;AAGxC,qBAAiC;AACjC,qBAA0B;AAzC1B;AA2CO,MAAM,YAA8B;AAAA,EAiF1C,YAAY;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAA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_EnokiFlow {
|
|
|
32
32
|
provider: AuthProvider;
|
|
33
33
|
clientId: string;
|
|
34
34
|
redirectUrl: string;
|
|
35
|
-
extraParams?: Record<string,
|
|
35
|
+
extraParams?: Record<string, string>;
|
|
36
36
|
}): Promise<string>;
|
|
37
37
|
handleAuthCallback(hash?: string): Promise<string | null>;
|
|
38
38
|
getSession(): Promise<ZkLoginSession | null>;
|
package/dist/cjs/wallet/state.js
CHANGED
|
@@ -98,7 +98,7 @@ class INTERNAL_ONLY_EnokiFlow {
|
|
|
98
98
|
scope: [
|
|
99
99
|
"openid",
|
|
100
100
|
// Merge the requested scopes in with the required openid scopes:
|
|
101
|
-
...input.extraParams
|
|
101
|
+
...input.extraParams?.scope ? input.extraParams.scope.split(" ") : []
|
|
102
102
|
].filter(Boolean).join(" ")
|
|
103
103
|
});
|
|
104
104
|
let oauthUrl;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/wallet/state.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ExportedWebCryptoKeypair } from '@mysten/signers/webcrypto';\nimport { WebCryptoSigner } from '@mysten/signers/webcrypto';\nimport { decodeJwt } from '@mysten/sui/zklogin';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';\nimport type { UseStore } from 'idb-keyval';\nimport { clear, createStore, get, set } from 'idb-keyval';\nimport type { WritableAtom } from 'nanostores';\nimport { atom, onMount, onSet } from 'nanostores';\n\nimport type { Encryption } from '../encryption.js';\nimport { createDefaultEncryption } from '../encryption.js';\nimport type { EnokiClientConfig } from '../EnokiClient/index.js';\nimport { EnokiClient } from '../EnokiClient/index.js';\nimport type { AuthProvider, EnokiNetwork } from '../EnokiClient/type.js';\nimport { EnokiKeypair } from '../EnokiKeypair.js';\nimport type { SyncStore } from '../stores.js';\nimport { createSessionStorage } from '../stores.js';\n\ntype EnokiFlowConfig = EnokiClientConfig & { network: EnokiNetwork };\n\n// State that is not bound to a session, and is encrypted.\ninterface ZkLoginState {\n\tprovider?: AuthProvider;\n\taddress?: string;\n\tsalt?: string;\n\tpublicKey?: string;\n}\n\n// State that session-bound, and is encrypted in storage.\ninterface ZkLoginSession {\n\tmaxEpoch: number;\n\trandomness: string;\n\texpiresAt: number;\n\n\tjwt?: string;\n\tproof?: ZkLoginSignatureInputs;\n}\n\nconst createStorageKeys = (apiKey: string, network: EnokiNetwork) => ({\n\tSTATE: `@enoki/flow/state/${apiKey}/${network}`,\n\tSESSION: `@enoki/flow/session/${apiKey}/${network}`,\n});\n\nexport class INTERNAL_ONLY_EnokiFlow {\n\t#storageKeys: { STATE: string; SESSION: string };\n\t#enokiClient: EnokiClient;\n\t#network: EnokiNetwork;\n\t#encryption: Encryption;\n\t#encryptionKey: string;\n\t#store: SyncStore;\n\t#idbStore: UseStore;\n\n\t$zkLoginSession: WritableAtom<{ initialized: boolean; value: ZkLoginSession | null }>;\n\t$zkLoginState: WritableAtom<ZkLoginState>;\n\n\tconstructor(config: EnokiFlowConfig) {\n\t\tthis.#enokiClient = new EnokiClient({\n\t\t\tapiKey: config.apiKey,\n\t\t\tapiUrl: config.apiUrl,\n\t\t});\n\t\tthis.#network = config.network;\n\t\tthis.#encryptionKey = config.apiKey;\n\t\tthis.#encryption = createDefaultEncryption();\n\t\tthis.#store = createSessionStorage();\n\t\tthis.#storageKeys = createStorageKeys(config.apiKey, this.#network);\n\t\tthis.#idbStore = createStore('enoki', `${config.apiKey}_${this.#network}`);\n\n\t\tlet storedState = null;\n\t\ttry {\n\t\t\tconst rawStoredValue = this.#store.get(this.#storageKeys.STATE);\n\t\t\tif (rawStoredValue) {\n\t\t\t\tstoredState = JSON.parse(rawStoredValue);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore errors\n\t\t}\n\n\t\tthis.$zkLoginState = atom(storedState || {});\n\t\tthis.$zkLoginSession = atom({ initialized: false, value: null });\n\n\t\t// Hydrate the session on mount:\n\t\tonMount(this.$zkLoginSession, () => {\n\t\t\tthis.getSession();\n\t\t});\n\n\t\tonSet(this.$zkLoginState, ({ newValue }) => {\n\t\t\tthis.#store.set(this.#storageKeys.STATE, JSON.stringify(newValue));\n\t\t});\n\t}\n\n\tget network() {\n\t\treturn this.#network;\n\t}\n\n\tasync createAuthorizationURL(input: {\n\t\tprovider: AuthProvider;\n\t\tclientId: string;\n\t\tredirectUrl: string;\n\t\textraParams?: Record<string,
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,uBAAgC;AAChC,qBAA0B;AAG1B,wBAA6C;AAE7C,wBAAqC;AAGrC,wBAAwC;AAExC,yBAA4B;AAE5B,0BAA6B;AAE7B,oBAAqC;AAnBrC;AAyCA,MAAM,oBAAoB,CAAC,QAAgB,aAA2B;AAAA,EACrE,OAAO,qBAAqB,MAAM,IAAI,OAAO;AAAA,EAC7C,SAAS,uBAAuB,MAAM,IAAI,OAAO;AAClD;AAEO,MAAM,wBAAwB;AAAA,EAYpC,YAAY,QAAyB;AAZ/B;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AAMC,uBAAK,cAAe,IAAI,+BAAY;AAAA,MACnC,QAAQ,OAAO;AAAA,MACf,QAAQ,OAAO;AAAA,IAChB,CAAC;AACD,uBAAK,UAAW,OAAO;AACvB,uBAAK,gBAAiB,OAAO;AAC7B,uBAAK,iBAAc,2CAAwB;AAC3C,uBAAK,YAAS,oCAAqB;AACnC,uBAAK,cAAe,kBAAkB,OAAO,QAAQ,mBAAK,SAAQ;AAClE,uBAAK,eAAY,+BAAY,SAAS,GAAG,OAAO,MAAM,IAAI,mBAAK,SAAQ,EAAE;AAEzE,QAAI,cAAc;AAClB,QAAI;AACH,YAAM,iBAAiB,mBAAK,QAAO,IAAI,mBAAK,cAAa,KAAK;AAC9D,UAAI,gBAAgB;AACnB,sBAAc,KAAK,MAAM,cAAc;AAAA,MACxC;AAAA,IACD,QAAQ;AAAA,IAER;AAEA,SAAK,oBAAgB,wBAAK,eAAe,CAAC,CAAC;AAC3C,SAAK,sBAAkB,wBAAK,EAAE,aAAa,OAAO,OAAO,KAAK,CAAC;AAG/D,mCAAQ,KAAK,iBAAiB,MAAM;AACnC,WAAK,WAAW;AAAA,IACjB,CAAC;AAED,iCAAM,KAAK,eAAe,CAAC,EAAE,SAAS,MAAM;AAC3C,yBAAK,QAAO,IAAI,mBAAK,cAAa,OAAO,KAAK,UAAU,QAAQ,CAAC;AAAA,IAClE,CAAC;AAAA,EACF;AAAA,EAEA,IAAI,UAAU;AACb,WAAO,mBAAK;AAAA,EACb;AAAA,EAEA,MAAM,uBAAuB,OAK1B;AACF,UAAM,mBAAmB,MAAM,iCAAgB,SAAS;AACxD,UAAM,EAAE,OAAO,YAAY,UAAU,oBAAoB,IACxD,MAAM,mBAAK,cAAa,mBAAmB;AAAA,MAC1C,SAAS,mBAAK;AAAA,MACd,oBAAoB,iBAAiB,aAAa;AAAA,IACnD,CAAC;AAEF,UAAM,SAAS,IAAI,gBAAgB;AAAA,MAClC,GAAG,MAAM;AAAA,MACT;AAAA,MACA,WAAW,MAAM;AAAA,MACjB,cAAc,MAAM;AAAA,MACpB,eAAe;AAAA;AAAA,MAEf,OAAO;AAAA,QACN;AAAA;AAAA,QAEA,GAAI,MAAM,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ExportedWebCryptoKeypair } from '@mysten/signers/webcrypto';\nimport { WebCryptoSigner } from '@mysten/signers/webcrypto';\nimport { decodeJwt } from '@mysten/sui/zklogin';\nimport type { ZkLoginSignatureInputs } from '@mysten/sui/zklogin';\nimport type { UseStore } from 'idb-keyval';\nimport { clear, createStore, get, set } from 'idb-keyval';\nimport type { WritableAtom } from 'nanostores';\nimport { atom, onMount, onSet } from 'nanostores';\n\nimport type { Encryption } from '../encryption.js';\nimport { createDefaultEncryption } from '../encryption.js';\nimport type { EnokiClientConfig } from '../EnokiClient/index.js';\nimport { EnokiClient } from '../EnokiClient/index.js';\nimport type { AuthProvider, EnokiNetwork } from '../EnokiClient/type.js';\nimport { EnokiKeypair } from '../EnokiKeypair.js';\nimport type { SyncStore } from '../stores.js';\nimport { createSessionStorage } from '../stores.js';\n\ntype EnokiFlowConfig = EnokiClientConfig & { network: EnokiNetwork };\n\n// State that is not bound to a session, and is encrypted.\ninterface ZkLoginState {\n\tprovider?: AuthProvider;\n\taddress?: string;\n\tsalt?: string;\n\tpublicKey?: string;\n}\n\n// State that session-bound, and is encrypted in storage.\ninterface ZkLoginSession {\n\tmaxEpoch: number;\n\trandomness: string;\n\texpiresAt: number;\n\n\tjwt?: string;\n\tproof?: ZkLoginSignatureInputs;\n}\n\nconst createStorageKeys = (apiKey: string, network: EnokiNetwork) => ({\n\tSTATE: `@enoki/flow/state/${apiKey}/${network}`,\n\tSESSION: `@enoki/flow/session/${apiKey}/${network}`,\n});\n\nexport class INTERNAL_ONLY_EnokiFlow {\n\t#storageKeys: { STATE: string; SESSION: string };\n\t#enokiClient: EnokiClient;\n\t#network: EnokiNetwork;\n\t#encryption: Encryption;\n\t#encryptionKey: string;\n\t#store: SyncStore;\n\t#idbStore: UseStore;\n\n\t$zkLoginSession: WritableAtom<{ initialized: boolean; value: ZkLoginSession | null }>;\n\t$zkLoginState: WritableAtom<ZkLoginState>;\n\n\tconstructor(config: EnokiFlowConfig) {\n\t\tthis.#enokiClient = new EnokiClient({\n\t\t\tapiKey: config.apiKey,\n\t\t\tapiUrl: config.apiUrl,\n\t\t});\n\t\tthis.#network = config.network;\n\t\tthis.#encryptionKey = config.apiKey;\n\t\tthis.#encryption = createDefaultEncryption();\n\t\tthis.#store = createSessionStorage();\n\t\tthis.#storageKeys = createStorageKeys(config.apiKey, this.#network);\n\t\tthis.#idbStore = createStore('enoki', `${config.apiKey}_${this.#network}`);\n\n\t\tlet storedState = null;\n\t\ttry {\n\t\t\tconst rawStoredValue = this.#store.get(this.#storageKeys.STATE);\n\t\t\tif (rawStoredValue) {\n\t\t\t\tstoredState = JSON.parse(rawStoredValue);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore errors\n\t\t}\n\n\t\tthis.$zkLoginState = atom(storedState || {});\n\t\tthis.$zkLoginSession = atom({ initialized: false, value: null });\n\n\t\t// Hydrate the session on mount:\n\t\tonMount(this.$zkLoginSession, () => {\n\t\t\tthis.getSession();\n\t\t});\n\n\t\tonSet(this.$zkLoginState, ({ newValue }) => {\n\t\t\tthis.#store.set(this.#storageKeys.STATE, JSON.stringify(newValue));\n\t\t});\n\t}\n\n\tget network() {\n\t\treturn this.#network;\n\t}\n\n\tasync createAuthorizationURL(input: {\n\t\tprovider: AuthProvider;\n\t\tclientId: string;\n\t\tredirectUrl: string;\n\t\textraParams?: Record<string, string>;\n\t}) {\n\t\tconst ephemeralKeyPair = await WebCryptoSigner.generate();\n\t\tconst { nonce, randomness, maxEpoch, estimatedExpiration } =\n\t\t\tawait this.#enokiClient.createZkLoginNonce({\n\t\t\t\tnetwork: this.#network,\n\t\t\t\tephemeralPublicKey: ephemeralKeyPair.getPublicKey(),\n\t\t\t});\n\n\t\tconst params = new URLSearchParams({\n\t\t\t...input.extraParams,\n\t\t\tnonce,\n\t\t\tclient_id: input.clientId,\n\t\t\tredirect_uri: input.redirectUrl,\n\t\t\tresponse_type: 'id_token',\n\t\t\t// TODO: Eventually fetch the scopes for this client ID from the Enoki service:\n\t\t\tscope: [\n\t\t\t\t'openid',\n\t\t\t\t// Merge the requested scopes in with the required openid scopes:\n\t\t\t\t...(input.extraParams?.scope ? input.extraParams.scope.split(' ') : []),\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' '),\n\t\t});\n\n\t\tlet oauthUrl: string;\n\t\tswitch (input.provider) {\n\t\t\tcase 'google': {\n\t\t\t\toauthUrl = `https://accounts.google.com/o/oauth2/v2/auth?${params}`;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'facebook': {\n\t\t\t\toauthUrl = `https://www.facebook.com/v17.0/dialog/oauth?${params}`;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'twitch': {\n\t\t\t\tparams.set('force_verify', 'true');\n\t\t\t\toauthUrl = `https://id.twitch.tv/oauth2/authorize?${params}`;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Invalid provider: ${input.provider}`);\n\t\t}\n\n\t\tthis.$zkLoginState.set({ provider: input.provider });\n\n\t\tawait set('ephemeralKeyPair', ephemeralKeyPair.export(), this.#idbStore);\n\t\tawait this.#setSession({\n\t\t\texpiresAt: estimatedExpiration,\n\t\t\tmaxEpoch,\n\t\t\trandomness,\n\t\t});\n\n\t\treturn oauthUrl;\n\t}\n\n\tasync handleAuthCallback(hash: string = window.location.hash) {\n\t\tconst params = new URLSearchParams(hash.startsWith('#') ? hash.slice(1) : hash);\n\n\t\t// Before we handle the auth redirect and get the state, we need to restore it:\n\t\tconst zkp = await this.getSession();\n\n\t\tif (!zkp || !zkp.maxEpoch || !zkp.randomness) {\n\t\t\tthrow new Error(\n\t\t\t\t'Start of sign-in flow could not be found. Ensure you have started the sign-in flow before calling this.',\n\t\t\t);\n\t\t}\n\n\t\tconst jwt = params.get('id_token');\n\t\tif (!jwt) {\n\t\t\tthrow new Error('Missing ID Token');\n\t\t}\n\n\t\tdecodeJwt(jwt);\n\n\t\tconst { address, salt, publicKey } = await this.#enokiClient.getZkLogin({ jwt });\n\n\t\tthis.$zkLoginState.set({\n\t\t\t...this.$zkLoginState.get(),\n\t\t\tsalt,\n\t\t\taddress,\n\t\t\tpublicKey,\n\t\t});\n\t\tawait this.#setSession({\n\t\t\t...zkp,\n\t\t\tjwt,\n\t\t});\n\n\t\treturn params.get('state');\n\t}\n\n\tasync #setSession(newValue: ZkLoginSession | null) {\n\t\tif (newValue) {\n\t\t\tconst storedValue = await this.#encryption.encrypt(\n\t\t\t\tthis.#encryptionKey,\n\t\t\t\tJSON.stringify(newValue),\n\t\t\t);\n\n\t\t\tthis.#store.set(this.#storageKeys.SESSION, storedValue);\n\t\t} else {\n\t\t\tthis.#store.delete(this.#storageKeys.SESSION);\n\t\t}\n\n\t\tthis.$zkLoginSession.set({ initialized: true, value: newValue });\n\t}\n\n\tasync getSession() {\n\t\tif (this.$zkLoginSession.get().initialized) {\n\t\t\treturn this.$zkLoginSession.get().value;\n\t\t}\n\n\t\ttry {\n\t\t\tconst storedValue = this.#store.get(this.#storageKeys.SESSION);\n\t\t\tif (!storedValue) return null;\n\n\t\t\tconst state: ZkLoginSession = JSON.parse(\n\t\t\t\tawait this.#encryption.decrypt(this.#encryptionKey, storedValue),\n\t\t\t);\n\n\t\t\t// TODO: Rather than having expiration act as a logout, we should keep the state that still is relevant,\n\t\t\t// and just clear out the expired session, but keep the other zkLogin state.\n\t\t\tif (state?.expiresAt && Date.now() > state.expiresAt) {\n\t\t\t\tawait this.logout();\n\t\t\t} else {\n\t\t\t\tthis.$zkLoginSession.set({ initialized: true, value: state });\n\t\t\t}\n\t\t} catch {\n\t\t\tthis.$zkLoginSession.set({ initialized: true, value: null });\n\t\t}\n\n\t\treturn this.$zkLoginSession.get().value;\n\t}\n\n\tasync logout() {\n\t\tthis.$zkLoginState.set({});\n\t\tthis.#store.delete(this.#storageKeys.STATE);\n\n\t\tawait clear(this.#idbStore);\n\t\tawait this.#setSession(null);\n\t}\n\n\t// TODO: Should this return the proof if it already exists?\n\tasync getProof() {\n\t\tconst zkp = await this.getSession();\n\t\tconst { salt } = this.$zkLoginState.get();\n\n\t\tif (zkp?.proof) {\n\t\t\tif (zkp.expiresAt && Date.now() > zkp.expiresAt) {\n\t\t\t\tthrow new Error('Stored proof is expired.');\n\t\t\t}\n\n\t\t\treturn zkp.proof;\n\t\t}\n\n\t\tif (!salt || !zkp || !zkp.jwt) {\n\t\t\tthrow new Error('Missing required parameters for proof generation');\n\t\t}\n\n\t\tconst storedNativeSigner = await get<ExportedWebCryptoKeypair>(\n\t\t\t'ephemeralKeyPair',\n\t\t\tthis.#idbStore,\n\t\t);\n\t\tif (!storedNativeSigner) {\n\t\t\tthrow new Error('Native signer not found in store.');\n\t\t}\n\n\t\tconst ephemeralKeyPair = WebCryptoSigner.import(storedNativeSigner);\n\n\t\tconst proof = await this.#enokiClient.createZkLoginZkp({\n\t\t\tnetwork: this.#network,\n\t\t\tjwt: zkp.jwt,\n\t\t\tmaxEpoch: zkp.maxEpoch,\n\t\t\trandomness: zkp.randomness,\n\t\t\tephemeralPublicKey: ephemeralKeyPair.getPublicKey(),\n\t\t});\n\n\t\tawait this.#setSession({\n\t\t\t...zkp,\n\t\t\tproof,\n\t\t});\n\n\t\treturn proof;\n\t}\n\n\tasync getKeypair() {\n\t\t// Get the proof, so that we ensure it exists in state:\n\t\tawait this.getProof();\n\n\t\tconst zkp = await this.getSession();\n\n\t\t// Check to see if we have the essentials for a keypair:\n\t\tconst { address } = this.$zkLoginState.get();\n\t\tif (!address || !zkp || !zkp.proof) {\n\t\t\tthrow new Error('Missing required data for keypair generation.');\n\t\t}\n\n\t\tif (Date.now() > zkp.expiresAt) {\n\t\t\tthrow new Error('Stored proof is expired.');\n\t\t}\n\n\t\tconst storedNativeSigner = await get<ExportedWebCryptoKeypair>(\n\t\t\t'ephemeralKeyPair',\n\t\t\tthis.#idbStore,\n\t\t);\n\n\t\tif (!storedNativeSigner) {\n\t\t\tthrow new Error('Native signer not found in store.');\n\t\t}\n\n\t\tconst ephemeralKeypair = WebCryptoSigner.import(storedNativeSigner);\n\n\t\treturn new EnokiKeypair({\n\t\t\taddress,\n\t\t\tephemeralKeypair,\n\t\t\tmaxEpoch: zkp.maxEpoch,\n\t\t\tproof: zkp.proof,\n\t\t});\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,uBAAgC;AAChC,qBAA0B;AAG1B,wB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,MAAM,+CAA+C;AAAA,IAChE;AAEA,QAAI,KAAK,IAAI,IAAI,IAAI,WAAW;AAC/B,YAAM,IAAI,MAAM,0BAA0B;AAAA,IAC3C;AAEA,UAAM,qBAAqB,UAAM;AAAA,MAChC;AAAA,MACA,mBAAK;AAAA,IACN;AAEA,QAAI,CAAC,oBAAoB;AACxB,YAAM,IAAI,MAAM,mCAAmC;AAAA,IACpD;AAEA,UAAM,mBAAmB,iCAAgB,OAAO,kBAAkB;AAElE,WAAO,IAAI,iCAAa;AAAA,MACvB;AAAA,MACA;AAAA,MACA,UAAU,IAAI;AAAA,MACd,OAAO,IAAI;AAAA,IACZ,CAAC;AAAA,EACF;AACD;AAhRC;AACA;AACA;AACA;AACA;AACA;AACA;AAPM;AAkJA,gBAAW,eAAC,UAAiC;AAClD,MAAI,UAAU;AACb,UAAM,cAAc,MAAM,mBAAK,aAAY;AAAA,MAC1C,mBAAK;AAAA,MACL,KAAK,UAAU,QAAQ;AAAA,IACxB;AAEA,uBAAK,QAAO,IAAI,mBAAK,cAAa,SAAS,WAAW;AAAA,EACvD,OAAO;AACN,uBAAK,QAAO,OAAO,mBAAK,cAAa,OAAO;AAAA,EAC7C;AAEA,OAAK,gBAAgB,IAAI,EAAE,aAAa,MAAM,OAAO,SAAS,CAAC;AAChE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Wallet } from '@mysten/wallet-standard';
|
|
2
|
+
import type { UiWallet } from '@wallet-standard/ui';
|
|
3
|
+
import type { EnokiWallet } from './index.js';
|
|
4
|
+
export declare function isEnokiWallet(wallet: UiWallet): boolean;
|
|
5
|
+
export declare function isEnokiWallet(wallet: Wallet): wallet is EnokiWallet;
|
|
6
|
+
export declare function getWalletMetadata(wallet: Wallet | UiWallet): import("./feature.js").EnokiGetMetadataOutput | null;
|
|
7
|
+
export declare function isGoogleWallet(wallet: Wallet | UiWallet): boolean;
|
|
8
|
+
export declare function isTwitchWallet(wallet: Wallet | UiWallet): boolean;
|
|
9
|
+
export declare function isFacebookWallet(wallet: Wallet | UiWallet): boolean;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
getWalletMetadata: () => getWalletMetadata,
|
|
22
|
+
isEnokiWallet: () => isEnokiWallet,
|
|
23
|
+
isFacebookWallet: () => isFacebookWallet,
|
|
24
|
+
isGoogleWallet: () => isGoogleWallet,
|
|
25
|
+
isTwitchWallet: () => isTwitchWallet
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(utils_exports);
|
|
28
|
+
var import_ui = require("@wallet-standard/ui");
|
|
29
|
+
var import_feature = require("./feature.js");
|
|
30
|
+
function isEnokiWallet(wallet) {
|
|
31
|
+
if (isWalletHandle(wallet)) {
|
|
32
|
+
return wallet.features.includes(import_feature.EnokiGetMetadata);
|
|
33
|
+
}
|
|
34
|
+
return import_feature.EnokiGetMetadata in wallet.features;
|
|
35
|
+
}
|
|
36
|
+
function getWalletMetadata(wallet) {
|
|
37
|
+
if (isWalletHandle(wallet)) {
|
|
38
|
+
try {
|
|
39
|
+
const { getMetadata } = (0, import_ui.getWalletFeature)(
|
|
40
|
+
wallet,
|
|
41
|
+
import_feature.EnokiGetMetadata
|
|
42
|
+
);
|
|
43
|
+
return getMetadata();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
} else if (import_feature.EnokiGetMetadata in wallet.features) {
|
|
48
|
+
const walletWithFeature = wallet;
|
|
49
|
+
return walletWithFeature.features[import_feature.EnokiGetMetadata].getMetadata();
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function isGoogleWallet(wallet) {
|
|
54
|
+
return getWalletMetadata(wallet)?.provider === "google";
|
|
55
|
+
}
|
|
56
|
+
function isTwitchWallet(wallet) {
|
|
57
|
+
return getWalletMetadata(wallet)?.provider === "twitch";
|
|
58
|
+
}
|
|
59
|
+
function isFacebookWallet(wallet) {
|
|
60
|
+
return getWalletMetadata(wallet)?.provider === "facebook";
|
|
61
|
+
}
|
|
62
|
+
function isWalletHandle(wallet) {
|
|
63
|
+
return Array.isArray(wallet.features);
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/wallet/utils.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Wallet, WalletWithFeatures } from '@mysten/wallet-standard';\nimport type { UiWallet } from '@wallet-standard/ui';\nimport { getWalletFeature } from '@wallet-standard/ui';\nimport type { EnokiWallet } from './index.js';\nimport type { EnokiGetMetadataFeature } from './feature.js';\nimport { EnokiGetMetadata } from './feature.js';\n\nexport function isEnokiWallet(wallet: UiWallet): boolean;\nexport function isEnokiWallet(wallet: Wallet): wallet is EnokiWallet;\nexport function isEnokiWallet(wallet: Wallet | UiWallet) {\n\tif (isWalletHandle(wallet)) {\n\t\treturn wallet.features.includes(EnokiGetMetadata);\n\t}\n\treturn EnokiGetMetadata in wallet.features;\n}\n\nexport function getWalletMetadata(wallet: Wallet | UiWallet) {\n\tif (isWalletHandle(wallet)) {\n\t\ttry {\n\t\t\tconst { getMetadata } = getWalletFeature(\n\t\t\t\twallet,\n\t\t\t\tEnokiGetMetadata,\n\t\t\t) as EnokiGetMetadataFeature[typeof EnokiGetMetadata];\n\n\t\t\treturn getMetadata();\n\t\t} catch (error) {\n\t\t\treturn null;\n\t\t}\n\t} else if (EnokiGetMetadata in wallet.features) {\n\t\tconst walletWithFeature = wallet as WalletWithFeatures<EnokiGetMetadataFeature>;\n\t\treturn walletWithFeature.features[EnokiGetMetadata].getMetadata();\n\t}\n\treturn null;\n}\n\nexport function isGoogleWallet(wallet: Wallet | UiWallet) {\n\treturn getWalletMetadata(wallet)?.provider === 'google';\n}\n\nexport function isTwitchWallet(wallet: Wallet | UiWallet) {\n\treturn getWalletMetadata(wallet)?.provider === 'twitch';\n}\n\nexport function isFacebookWallet(wallet: Wallet | UiWallet) {\n\treturn getWalletMetadata(wallet)?.provider === 'facebook';\n}\n\nfunction isWalletHandle(wallet: UiWallet | Wallet): wallet is UiWallet {\n\t// TypeScript doesn't properly narrow readonly arrays:\n\t// https://github.com/microsoft/TypeScript/issues/1700\n\treturn Array.isArray(wallet.features);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,gBAAiC;AAGjC,qBAAiC;AAI1B,SAAS,cAAc,QAA2B;AACxD,MAAI,eAAe,MAAM,GAAG;AAC3B,WAAO,OAAO,SAAS,SAAS,+BAAgB;AAAA,EACjD;AACA,SAAO,mCAAoB,OAAO;AACnC;AAEO,SAAS,kBAAkB,QAA2B;AAC5D,MAAI,eAAe,MAAM,GAAG;AAC3B,QAAI;AACH,YAAM,EAAE,YAAY,QAAI;AAAA,QACvB;AAAA,QACA;AAAA,MACD;AAEA,aAAO,YAAY;AAAA,IACpB,SAAS,OAAO;AACf,aAAO;AAAA,IACR;AAAA,EACD,WAAW,mCAAoB,OAAO,UAAU;AAC/C,UAAM,oBAAoB;AAC1B,WAAO,kBAAkB,SAAS,+BAAgB,EAAE,YAAY;AAAA,EACjE;AACA,SAAO;AACR;AAEO,SAAS,eAAe,QAA2B;AACzD,SAAO,kBAAkB,MAAM,GAAG,aAAa;AAChD;AAEO,SAAS,eAAe,QAA2B;AACzD,SAAO,kBAAkB,MAAM,GAAG,aAAa;AAChD;AAEO,SAAS,iBAAiB,QAA2B;AAC3D,SAAO,kBAAkB,MAAM,GAAG,aAAa;AAChD;AAEA,SAAS,eAAe,QAA+C;AAGtE,SAAO,MAAM,QAAQ,OAAO,QAAQ;AACrC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { EnokiFlow, type EnokiFlowConfig } from './EnokiFlow.js';
|
|
|
4
4
|
export { createLocalStorage, createSessionStorage, createInMemoryStorage, type SyncStore, } from './stores.js';
|
|
5
5
|
export { createDefaultEncryption, type Encryption } from './encryption.js';
|
|
6
6
|
export { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';
|
|
7
|
-
export {
|
|
7
|
+
export { registerEnokiWallets, type EnokiWallet } from './wallet/index.js';
|
|
8
|
+
export { isEnokiWallet, isGoogleWallet, isTwitchWallet, isFacebookWallet, getWalletMetadata, } from './wallet/utils.js';
|
|
8
9
|
export { type RegisterEnokiWalletsOptions } from './wallet/types.js';
|
|
9
10
|
export { isEnokiNetwork } from './utils.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -7,7 +7,14 @@ import {
|
|
|
7
7
|
} from "./stores.js";
|
|
8
8
|
import { createDefaultEncryption } from "./encryption.js";
|
|
9
9
|
import { EnokiKeypair, EnokiPublicKey } from "./EnokiKeypair.js";
|
|
10
|
-
import {
|
|
10
|
+
import { registerEnokiWallets } from "./wallet/index.js";
|
|
11
|
+
import {
|
|
12
|
+
isEnokiWallet,
|
|
13
|
+
isGoogleWallet,
|
|
14
|
+
isTwitchWallet,
|
|
15
|
+
isFacebookWallet,
|
|
16
|
+
getWalletMetadata
|
|
17
|
+
} from "./wallet/utils.js";
|
|
11
18
|
import { isEnokiNetwork } from "./utils.js";
|
|
12
19
|
export {
|
|
13
20
|
EnokiClient,
|
|
@@ -19,8 +26,12 @@ export {
|
|
|
19
26
|
createInMemoryStorage,
|
|
20
27
|
createLocalStorage,
|
|
21
28
|
createSessionStorage,
|
|
29
|
+
getWalletMetadata,
|
|
22
30
|
isEnokiNetwork,
|
|
23
31
|
isEnokiWallet,
|
|
32
|
+
isFacebookWallet,
|
|
33
|
+
isGoogleWallet,
|
|
34
|
+
isTwitchWallet,
|
|
24
35
|
registerEnokiWallets
|
|
25
36
|
};
|
|
26
37
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { EnokiClient, type EnokiClientConfig, EnokiClientError } from './EnokiClient/index.js';\nexport type { EnokiNetwork, AuthProvider } from './EnokiClient/type.js';\nexport { EnokiFlow, type EnokiFlowConfig } from './EnokiFlow.js';\nexport {\n\tcreateLocalStorage,\n\tcreateSessionStorage,\n\tcreateInMemoryStorage,\n\ttype SyncStore,\n} from './stores.js';\nexport { createDefaultEncryption, type Encryption } from './encryption.js';\nexport { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';\n\nexport {
|
|
5
|
-
"mappings": "AAGA,SAAS,aAAqC,wBAAwB;AAEtE,SAAS,iBAAuC;AAChD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP,SAAS,+BAAgD;AACzD,SAAS,cAAc,sBAAsB;AAE7C,SAAS,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { EnokiClient, type EnokiClientConfig, EnokiClientError } from './EnokiClient/index.js';\nexport type { EnokiNetwork, AuthProvider } from './EnokiClient/type.js';\nexport { EnokiFlow, type EnokiFlowConfig } from './EnokiFlow.js';\nexport {\n\tcreateLocalStorage,\n\tcreateSessionStorage,\n\tcreateInMemoryStorage,\n\ttype SyncStore,\n} from './stores.js';\nexport { createDefaultEncryption, type Encryption } from './encryption.js';\nexport { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';\n\nexport { registerEnokiWallets, type EnokiWallet } from './wallet/index.js';\nexport {\n\tisEnokiWallet,\n\tisGoogleWallet,\n\tisTwitchWallet,\n\tisFacebookWallet,\n\tgetWalletMetadata,\n} from './wallet/utils.js';\nexport { type RegisterEnokiWalletsOptions } from './wallet/types.js';\n\nexport { isEnokiNetwork } from './utils.js';\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,aAAqC,wBAAwB;AAEtE,SAAS,iBAAuC;AAChD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP,SAAS,+BAAgD;AACzD,SAAS,cAAc,sBAAsB;AAE7C,SAAS,4BAA8C;AACvD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAGP,SAAS,sBAAsB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { decodeJwt } from '@mysten/sui/zklogin';
|
|
2
|
+
import type { AuthProvider } from '../EnokiClient/type.js';
|
|
3
|
+
/** Name of the feature. */
|
|
4
|
+
export declare const EnokiGetMetadata = "enoki:getMetadata";
|
|
5
|
+
/** The latest API version of the getEnokiMetadata API. */
|
|
6
|
+
export type EnokiGetMetadataVersion = '1.0.0';
|
|
7
|
+
/**
|
|
8
|
+
* A Wallet Standard feature for retreiving Enoki-specific metadata about the wallet.
|
|
9
|
+
*/
|
|
10
|
+
export type EnokiGetMetadataFeature = {
|
|
11
|
+
/** Namespace for the feature. */
|
|
12
|
+
[EnokiGetMetadata]: {
|
|
13
|
+
/** Version of the feature API. */
|
|
14
|
+
version: '1.0.0';
|
|
15
|
+
getMetadata: EnokiGetMetadataMethod;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type EnokiGetMetadataMethod = (input?: EnokiGetMetadataInput) => EnokiGetMetadataOutput;
|
|
19
|
+
/** Input for retrieving metadata about the wallet. */
|
|
20
|
+
export interface EnokiGetMetadataInput {
|
|
21
|
+
}
|
|
22
|
+
/** Output of retrieving metadata about the wallet. */
|
|
23
|
+
export interface EnokiGetMetadataOutput {
|
|
24
|
+
/** The social provider for the wallet. */
|
|
25
|
+
provider: AuthProvider;
|
|
26
|
+
/** Metadata pertaining to the active session. */
|
|
27
|
+
activeSession?: {
|
|
28
|
+
/** The decoded JWT for the session. */
|
|
29
|
+
decodedJwt: ReturnType<typeof decodeJwt>;
|
|
30
|
+
};
|
|
31
|
+
}
|