@mysten/enoki 0.10.0 → 0.11.1

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @mysten/enoki
2
2
 
3
+ ## 0.11.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [c76ddc5]
8
+ - @mysten/sui@1.36.1
9
+ - @mysten/signers@0.3.1
10
+ - @mysten/wallet-standard@0.16.6
11
+
12
+ ## 0.11.0
13
+
14
+ ### Minor Changes
15
+
16
+ - 5d0269c: Split the `enoki:getMetadata` feature into `enoki:getMetadata` and `enoki:getSession`.
17
+
18
+ `getWalletMetadata` now only returns the authentication provider, while `getSession` returns the
19
+ zkLogin session data.
20
+
3
21
  ## 0.10.0
4
22
 
5
23
  ### Minor Changes
@@ -7,6 +7,6 @@ export { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';
7
7
  export type { EnokiWallet } from './wallet/wallet.js';
8
8
  export { registerEnokiWallets } from './wallet/register.js';
9
9
  export { enokiWalletsInitializer } from './wallet/initializer.js';
10
- export { isEnokiWallet, isGoogleWallet, isTwitchWallet, isFacebookWallet, getWalletMetadata, } from './wallet/utils.js';
10
+ export { isEnokiWallet, isGoogleWallet, isTwitchWallet, isFacebookWallet, getWalletMetadata, getSession, } from './wallet/utils.js';
11
11
  export { type RegisterEnokiWalletsOptions } from './wallet/types.js';
12
12
  export { isEnokiNetwork } from './utils.js';
package/dist/cjs/index.js CHANGED
@@ -28,6 +28,7 @@ __export(index_exports, {
28
28
  createLocalStorage: () => import_stores.createLocalStorage,
29
29
  createSessionStorage: () => import_stores.createSessionStorage,
30
30
  enokiWalletsInitializer: () => import_initializer.enokiWalletsInitializer,
31
+ getSession: () => import_utils.getSession,
31
32
  getWalletMetadata: () => import_utils.getWalletMetadata,
32
33
  isEnokiNetwork: () => import_utils2.isEnokiNetwork,
33
34
  isEnokiWallet: () => import_utils.isEnokiWallet,
@@ -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 type { EnokiWallet } from './wallet/wallet.js';\nexport { registerEnokiWallets } from './wallet/register.js';\nexport { enokiWalletsInitializer } from './wallet/initializer.js';\n\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;AAAA;AAGA,yBAAsE;AAEtE,uBAAgD;AAChD,oBAKO;AACP,wBAAyD;AACzD,0BAA6C;AAG7C,sBAAqC;AACrC,yBAAwC;AAExC,mBAMO;AAGP,IAAAA,gBAA+B;",
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 type { EnokiWallet } from './wallet/wallet.js';\nexport { registerEnokiWallets } from './wallet/register.js';\nexport { enokiWalletsInitializer } from './wallet/initializer.js';\n\nexport {\n\tisEnokiWallet,\n\tisGoogleWallet,\n\tisTwitchWallet,\n\tisFacebookWallet,\n\tgetWalletMetadata,\n\tgetSession,\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;AAAA;AAAA;AAGA,yBAAsE;AAEtE,uBAAgD;AAChD,oBAKO;AACP,wBAAyD;AACzD,0BAA6C;AAG7C,sBAAqC;AACrC,yBAAwC;AAExC,mBAOO;AAGP,IAAAA,gBAA+B;",
6
6
  "names": ["import_utils"]
7
7
  }
@@ -0,0 +1,50 @@
1
+ import type { AuthProvider, EnokiNetwork } from '../EnokiClient/type.js';
2
+ import type { ZkLoginSession } from './types.js';
3
+ /** Name of the feature for retrieving basic wallet metadata. */
4
+ export declare const EnokiGetMetadata = "enoki:getMetadata";
5
+ /** The latest API version of the getMetadata 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: EnokiGetMetadataVersion;
15
+ getMetadata: EnokiGetMetadataMethod;
16
+ };
17
+ };
18
+ export type EnokiGetMetadataMethod = (input?: EnokiGetMetadataInput) => EnokiGetMetadataOutput;
19
+ /** Input for retrieving metadata about the wallet. */
20
+ export type EnokiGetMetadataInput = void;
21
+ /** Output of retrieving metadata about the wallet. */
22
+ export type EnokiGetMetadataOutput = {
23
+ /** The social provider for the wallet. */
24
+ provider: AuthProvider;
25
+ };
26
+ /** Name of the feature for retrieving the Enoki session. */
27
+ export declare const EnokiGetSession = "enoki:getSession";
28
+ /** The latest API version of the getSession API. */
29
+ export type EnokiGetSessionVersion = '1.0.0';
30
+ /**
31
+ * A Wallet Standard feature for retreiving the zkLogin session from the wallet.
32
+ */
33
+ export type EnokiGetSessionFeature = {
34
+ /** Namespace for the feature. */
35
+ [EnokiGetSession]: {
36
+ /** Version of the feature API. */
37
+ version: EnokiGetSessionVersion;
38
+ getSession: EnokiGetSessionMethod;
39
+ };
40
+ };
41
+ export type EnokiGetSessionMethod = (input?: EnokiGetSessionInput) => Promise<EnokiGetSessionOutput>;
42
+ /** Input for retrieving the session from the wallet. */
43
+ export type EnokiGetSessionInput = {
44
+ /**
45
+ * The network to retrieve session data for. Defaults to the active network.
46
+ **/
47
+ network?: EnokiNetwork;
48
+ };
49
+ /** Output of retrieving the Enoki session. */
50
+ export type EnokiGetSessionOutput = ZkLoginSession | null;
@@ -16,10 +16,12 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var feature_exports = {};
20
- __export(feature_exports, {
21
- EnokiGetMetadata: () => EnokiGetMetadata
19
+ var features_exports = {};
20
+ __export(features_exports, {
21
+ EnokiGetMetadata: () => EnokiGetMetadata,
22
+ EnokiGetSession: () => EnokiGetSession
22
23
  });
23
- module.exports = __toCommonJS(feature_exports);
24
+ module.exports = __toCommonJS(features_exports);
24
25
  const EnokiGetMetadata = "enoki:getMetadata";
25
- //# sourceMappingURL=feature.js.map
26
+ const EnokiGetSession = "enoki:getSession";
27
+ //# sourceMappingURL=features.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/wallet/features.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { AuthProvider, EnokiNetwork } from '../EnokiClient/type.js';\nimport type { ZkLoginSession } from './types.js';\n\n/** Name of the feature for retrieving basic wallet metadata. */\nexport const EnokiGetMetadata = 'enoki:getMetadata';\n\n/** The latest API version of the getMetadata 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: EnokiGetMetadataVersion;\n\t\tgetMetadata: EnokiGetMetadataMethod;\n\t};\n};\n\nexport type EnokiGetMetadataMethod = (input?: EnokiGetMetadataInput) => EnokiGetMetadataOutput;\n\n/** Input for retrieving metadata about the wallet. */\nexport type EnokiGetMetadataInput = void;\n\n/** Output of retrieving metadata about the wallet. */\nexport type EnokiGetMetadataOutput = {\n\t/** The social provider for the wallet. */\n\tprovider: AuthProvider;\n};\n\n/** Name of the feature for retrieving the Enoki session. */\nexport const EnokiGetSession = 'enoki:getSession';\n\n/** The latest API version of the getSession API. */\nexport type EnokiGetSessionVersion = '1.0.0';\n\n/**\n * A Wallet Standard feature for retreiving the zkLogin session from the wallet.\n */\nexport type EnokiGetSessionFeature = {\n\t/** Namespace for the feature. */\n\t[EnokiGetSession]: {\n\t\t/** Version of the feature API. */\n\t\tversion: EnokiGetSessionVersion;\n\t\tgetSession: EnokiGetSessionMethod;\n\t};\n};\n\nexport type EnokiGetSessionMethod = (\n\tinput?: EnokiGetSessionInput,\n) => Promise<EnokiGetSessionOutput>;\n\n/** Input for retrieving the session from the wallet. */\nexport type EnokiGetSessionInput = {\n\t/**\n\t * The network to retrieve session data for. Defaults to the active network.\n\t **/\n\tnetwork?: EnokiNetwork;\n};\n\n/** Output of retrieving the Enoki session. */\nexport type EnokiGetSessionOutput = ZkLoginSession | null;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,MAAM,mBAAmB;AA6BzB,MAAM,kBAAkB;",
6
+ "names": []
7
+ }
@@ -1,9 +1,11 @@
1
1
  import type { Wallet } from '@mysten/wallet-standard';
2
2
  import type { UiWallet } from '@wallet-standard/ui';
3
3
  import type { EnokiWallet } from './wallet.js';
4
+ import type { EnokiGetSessionInput } from './features.js';
4
5
  export declare function isEnokiWallet(wallet: UiWallet): boolean;
5
6
  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 getWalletMetadata(wallet: Wallet | UiWallet): import("./features.js").EnokiGetMetadataOutput | null;
8
+ export declare function getSession(wallet: Wallet | UiWallet, input?: EnokiGetSessionInput): Promise<import("./features.js").EnokiGetSessionOutput>;
7
9
  export declare function isGoogleWallet(wallet: Wallet | UiWallet): boolean;
8
10
  export declare function isTwitchWallet(wallet: Wallet | UiWallet): boolean;
9
11
  export declare function isFacebookWallet(wallet: Wallet | UiWallet): boolean;
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var utils_exports = {};
20
20
  __export(utils_exports, {
21
+ getSession: () => getSession,
21
22
  getWalletMetadata: () => getWalletMetadata,
22
23
  isEnokiWallet: () => isEnokiWallet,
23
24
  isFacebookWallet: () => isFacebookWallet,
@@ -26,27 +27,44 @@ __export(utils_exports, {
26
27
  });
27
28
  module.exports = __toCommonJS(utils_exports);
28
29
  var import_ui = require("@wallet-standard/ui");
29
- var import_feature = require("./feature.js");
30
+ var import_features = require("./features.js");
30
31
  function isEnokiWallet(wallet) {
31
32
  if (isWalletHandle(wallet)) {
32
- return wallet.features.includes(import_feature.EnokiGetMetadata);
33
+ return wallet.features.includes(import_features.EnokiGetMetadata);
33
34
  }
34
- return import_feature.EnokiGetMetadata in wallet.features;
35
+ return import_features.EnokiGetMetadata in wallet.features;
35
36
  }
36
37
  function getWalletMetadata(wallet) {
37
38
  if (isWalletHandle(wallet)) {
38
39
  try {
39
40
  const { getMetadata } = (0, import_ui.getWalletFeature)(
40
41
  wallet,
41
- import_feature.EnokiGetMetadata
42
+ import_features.EnokiGetMetadata
42
43
  );
43
44
  return getMetadata();
44
45
  } catch (error) {
45
46
  return null;
46
47
  }
47
- } else if (import_feature.EnokiGetMetadata in wallet.features) {
48
+ } else if (import_features.EnokiGetMetadata in wallet.features) {
48
49
  const walletWithFeature = wallet;
49
- return walletWithFeature.features[import_feature.EnokiGetMetadata].getMetadata();
50
+ return walletWithFeature.features[import_features.EnokiGetMetadata].getMetadata();
51
+ }
52
+ return null;
53
+ }
54
+ async function getSession(wallet, input) {
55
+ if (isWalletHandle(wallet)) {
56
+ try {
57
+ const { getSession: getSession2 } = (0, import_ui.getWalletFeature)(
58
+ wallet,
59
+ import_features.EnokiGetSession
60
+ );
61
+ return await getSession2(input);
62
+ } catch (error) {
63
+ return null;
64
+ }
65
+ } else if (import_features.EnokiGetSession in wallet.features) {
66
+ const walletWithFeature = wallet;
67
+ return await walletWithFeature.features[import_features.EnokiGetSession].getSession(input);
50
68
  }
51
69
  return null;
52
70
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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 './wallet.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": []
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 './wallet.js';\nimport type {\n\tEnokiGetMetadataFeature,\n\tEnokiGetSessionFeature,\n\tEnokiGetSessionInput,\n} from './features.js';\nimport { EnokiGetMetadata, EnokiGetSession } from './features.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 async function getSession(wallet: Wallet | UiWallet, input?: EnokiGetSessionInput) {\n\tif (isWalletHandle(wallet)) {\n\t\ttry {\n\t\t\tconst { getSession } = getWalletFeature(\n\t\t\t\twallet,\n\t\t\t\tEnokiGetSession,\n\t\t\t) as EnokiGetSessionFeature[typeof EnokiGetSession];\n\n\t\t\treturn await getSession(input);\n\t\t} catch (error) {\n\t\t\treturn null;\n\t\t}\n\t} else if (EnokiGetSession in wallet.features) {\n\t\tconst walletWithFeature = wallet as WalletWithFeatures<EnokiGetSessionFeature>;\n\t\treturn await walletWithFeature.features[EnokiGetSession].getSession(input);\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;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ature, StandardDisconnectFeature, StandardEventsF
2
2
  import { ReadonlyWalletAccount } from '@mysten/wallet-standard';
3
3
  import type { AuthProvider } from '../EnokiClient/type.js';
4
4
  import type { EnokiWalletOptions } from './types.js';
5
- import type { EnokiGetMetadataFeature } from './feature.js';
5
+ import type { EnokiGetMetadataFeature, EnokiGetSessionFeature } from './features.js';
6
6
  export declare class EnokiWallet implements Wallet {
7
7
  #private;
8
8
  get name(): string;
@@ -11,6 +11,6 @@ export declare class EnokiWallet implements Wallet {
11
11
  get version(): "1.0.0";
12
12
  get chains(): `sui:${string & {}}`[];
13
13
  get accounts(): ReadonlyWalletAccount[];
14
- get features(): StandardConnectFeature & StandardDisconnectFeature & StandardEventsFeature & SuiSignTransactionFeature & SuiSignAndExecuteTransactionFeature & SuiSignPersonalMessageFeature & EnokiGetMetadataFeature;
14
+ get features(): StandardConnectFeature & StandardDisconnectFeature & StandardEventsFeature & SuiSignTransactionFeature & SuiSignAndExecuteTransactionFeature & SuiSignPersonalMessageFeature & EnokiGetMetadataFeature & EnokiGetSessionFeature;
15
15
  constructor({ name, icon, provider, clientId, redirectUrl, extraParams, windowFeatures, getCurrentNetwork, apiKey, apiUrl, clients, }: EnokiWalletOptions);
16
16
  }
@@ -43,7 +43,7 @@ var import_transactions = require("@mysten/sui/transactions");
43
43
  var import_utils = require("@mysten/sui/utils");
44
44
  var import_wallet_standard = require("@mysten/wallet-standard");
45
45
  var import_mitt = __toESM(require("mitt"));
46
- var import_feature = require("./feature.js");
46
+ var import_features = require("./features.js");
47
47
  var import_zklogin = require("@mysten/sui/zklogin");
48
48
  var import_webcrypto = require("@mysten/signers/webcrypto");
49
49
  var import_idb_keyval = require("idb-keyval");
@@ -51,7 +51,7 @@ var import_EnokiClient = require("../EnokiClient/index.js");
51
51
  var import_EnokiKeypair = require("../EnokiKeypair.js");
52
52
  var import_state = require("./state.js");
53
53
  var import_nanostores = require("nanostores");
54
- var _events, _accounts, _name, _icon, _enokiClient, _state, _provider, _clientId, _redirectUrl, _extraParams, _getCurrentNetwork, _windowFeatures, _signTransaction, _signAndExecuteTransaction, _signPersonalMessage, _getMetadata, _on, _connect, _disconnect, _EnokiWallet_instances, getAuthorizedAccounts_fn, getKeypair_fn, getSignerContext_fn, createSession_fn, createAuthorizationURL_fn, handleAuthCallback_fn;
54
+ var _events, _accounts, _name, _icon, _enokiClient, _state, _provider, _clientId, _redirectUrl, _extraParams, _getCurrentNetwork, _windowFeatures, _signTransaction, _signAndExecuteTransaction, _signPersonalMessage, _getMetadata, _getSession, _on, _connect, _disconnect, _EnokiWallet_instances, getAuthorizedAccounts_fn, getKeypair_fn, getSignerContext_fn, createSession_fn, createAuthorizationURL_fn, handleAuthCallback_fn;
55
55
  class EnokiWallet {
56
56
  constructor({
57
57
  name,
@@ -131,14 +131,16 @@ class EnokiWallet {
131
131
  return keypair.signPersonalMessage(message);
132
132
  });
133
133
  __privateAdd(this, _getMetadata, () => {
134
- const sessionContext = __privateGet(this, _state).getSessionContext(__privateGet(this, _getCurrentNetwork).call(this));
135
- const session = sessionContext?.$zkLoginSession.get();
136
- const decodedJwt = session?.value?.jwt ? (0, import_zklogin.decodeJwt)(session.value.jwt) : void 0;
137
134
  return {
138
- provider: __privateGet(this, _provider),
139
- activeSession: decodedJwt ? { decodedJwt } : void 0
135
+ provider: __privateGet(this, _provider)
140
136
  };
141
137
  });
138
+ __privateAdd(this, _getSession, async (input) => {
139
+ const sessionContext = __privateGet(this, _state).getSessionContext(
140
+ input?.network ?? __privateGet(this, _getCurrentNetwork).call(this)
141
+ );
142
+ return await __privateGet(this, _state).getSession(sessionContext);
143
+ });
142
144
  __privateAdd(this, _on, (event, listener) => {
143
145
  __privateGet(this, _events).on(event, listener);
144
146
  return () => __privateGet(this, _events).off(event, listener);
@@ -220,9 +222,13 @@ class EnokiWallet {
220
222
  version: "1.1.0",
221
223
  signPersonalMessage: __privateGet(this, _signPersonalMessage)
222
224
  },
223
- [import_feature.EnokiGetMetadata]: {
225
+ [import_features.EnokiGetMetadata]: {
224
226
  version: "1.0.0",
225
227
  getMetadata: __privateGet(this, _getMetadata)
228
+ },
229
+ [import_features.EnokiGetSession]: {
230
+ version: "1.0.0",
231
+ getSession: __privateGet(this, _getSession)
226
232
  }
227
233
  };
228
234
  }
@@ -243,6 +249,7 @@ _signTransaction = new WeakMap();
243
249
  _signAndExecuteTransaction = new WeakMap();
244
250
  _signPersonalMessage = new WeakMap();
245
251
  _getMetadata = new WeakMap();
252
+ _getSession = new WeakMap();
246
253
  _on = new WeakMap();
247
254
  _connect = new WeakMap();
248
255
  _disconnect = new WeakMap();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/wallet/wallet.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\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\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 type { EnokiWalletOptions, WalletEventsMap, EnokiSessionContext } from './types.js';\nimport type { EnokiGetMetadataFeature, EnokiGetMetadataMethod } from './feature.js';\nimport { EnokiGetMetadata } from './feature.js';\nimport type { Experimental_SuiClientTypes } from '@mysten/sui/experimental';\nimport { decodeJwt } from '@mysten/sui/zklogin';\nimport type { ExportedWebCryptoKeypair } from '@mysten/signers/webcrypto';\nimport { WebCryptoSigner } from '@mysten/signers/webcrypto';\nimport { get, set } from 'idb-keyval';\n\nimport { EnokiClient } from '../EnokiClient/index.js';\nimport type { EnokiNetwork } from '../EnokiClient/type.js';\nimport { EnokiKeypair } from '../EnokiKeypair.js';\n\nimport { EnokiWalletState } from './state.js';\nimport { allTasks } from 'nanostores';\n\nexport class EnokiWallet implements Wallet {\n\t#events: Emitter<WalletEventsMap>;\n\t#accounts: ReadonlyWalletAccount[];\n\t#name: string;\n\t#icon: Wallet['icon'];\n\t#enokiClient: EnokiClient;\n\t#state: EnokiWalletState;\n\t#provider: AuthProvider;\n\t#clientId: string;\n\t#redirectUrl: string;\n\t#extraParams: Record<string, string> | (() => Record<string, string>) | undefined;\n\t#getCurrentNetwork: () => Experimental_SuiClientTypes.Network;\n\t#windowFeatures?: string | (() => string);\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 [...this.#state.sessionContextByNetwork.keys()].map(\n\t\t\t(network) => `sui:${network}` as const,\n\t\t);\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\tprovider,\n\t\tclientId,\n\t\tredirectUrl,\n\t\textraParams,\n\t\twindowFeatures,\n\t\tgetCurrentNetwork,\n\t\tapiKey,\n\t\tapiUrl,\n\t\tclients,\n\t}: EnokiWalletOptions) {\n\t\tthis.#events = mitt();\n\t\tthis.#name = name;\n\t\tthis.#icon = icon;\n\t\tthis.#enokiClient = new EnokiClient({ apiKey, apiUrl });\n\t\tthis.#state = new EnokiWalletState({ apiKey, clientId, clients });\n\t\tthis.#provider = provider;\n\t\tthis.#clientId = clientId;\n\t\tthis.#redirectUrl = redirectUrl || window.location.href.split('#')[0];\n\t\tthis.#extraParams = extraParams;\n\t\tthis.#windowFeatures = windowFeatures;\n\t\tthis.#getCurrentNetwork = getCurrentNetwork;\n\t\tthis.#accounts = [];\n\n\t\tthis.#state.zkLoginState.subscribe(() => {\n\t\t\tthis.#accounts = this.#getAuthorizedAccounts();\n\t\t\tthis.#events.emit('change', { accounts: this.#accounts });\n\t\t});\n\t}\n\n\t#signTransaction: SuiSignTransactionMethod = async ({ transaction, chain, account, signal }) => {\n\t\tsignal?.throwIfAborted();\n\n\t\tconst { client, keypair } = await this.#getSignerContext(chain);\n\t\tconst parsedTransaction = Transaction.from(await transaction.toJSON());\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 }));\n\t};\n\n\t#signAndExecuteTransaction: SuiSignAndExecuteTransactionMethod = async ({\n\t\ttransaction,\n\t\tchain,\n\t\taccount,\n\t\tsignal,\n\t}) => {\n\t\tsignal?.throwIfAborted();\n\n\t\tconst { client, keypair } = await this.#getSignerContext(chain);\n\t\tconst parsedTransaction = Transaction.from(await transaction.toJSON());\n\t\tconst bytes = await parsedTransaction.build({ client });\n\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\n\t\tconst result = await keypair.signAndExecuteTransaction({\n\t\t\ttransaction: parsedTransaction,\n\t\t\tclient,\n\t\t});\n\n\t\treturn {\n\t\t\tbytes: toBase64(bytes),\n\t\t\tsignature: result.signatures[0],\n\t\t\tdigest: result.digest,\n\t\t\teffects: toBase64(result.effects.bcs!),\n\t\t};\n\t};\n\n\t#signPersonalMessage: SuiSignPersonalMessageMethod = async ({ message, account, chain }) => {\n\t\tconst { keypair } = await this.#getSignerContext(chain);\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#getMetadata: EnokiGetMetadataMethod = () => {\n\t\tconst sessionContext = this.#state.getSessionContext(this.#getCurrentNetwork());\n\t\tconst session = sessionContext?.$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#on: StandardEventsOnMethod = (event, listener) => {\n\t\tthis.#events.on(event, listener);\n\t\treturn () => this.#events.off(event, listener);\n\t};\n\n\t#connect: StandardConnectMethod = async (input) => {\n\t\t// NOTE: This is a hackfix for the old version of dApp Kit where auto-connection logic\n\t\t// only fires on initial mount of the WalletProvider component. Since hydrating the\n\t\t// zkLogin state from IndexedDB is an asynchronous process, we need to make sure it\n\t\t// is populated before the connect logic runs.\n\t\tawait allTasks();\n\n\t\tif (input?.silent || this.#accounts.length > 0) {\n\t\t\treturn { accounts: this.#accounts };\n\t\t}\n\n\t\tconst currentNetwork = this.#getCurrentNetwork();\n\t\tawait this.#createSession({ network: currentNetwork });\n\n\t\treturn { accounts: this.#accounts };\n\t};\n\n\t#disconnect: StandardDisconnectMethod = async () => {\n\t\tawait this.#state.logout();\n\t\tthis.#accounts = [];\n\t\tthis.#events.emit('change', { accounts: this.#accounts });\n\t};\n\n\t#getAuthorizedAccounts() {\n\t\tconst zkLoginState = this.#state.zkLoginState.get();\n\t\tif (zkLoginState) {\n\t\t\treturn [\n\t\t\t\tnew ReadonlyWalletAccount({\n\t\t\t\t\taddress: zkLoginState.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(zkLoginState.publicKey),\n\t\t\t\t}),\n\t\t\t];\n\t\t}\n\t\treturn [];\n\t}\n\n\tasync #getKeypair(sessionContext: EnokiSessionContext) {\n\t\tconst session = await this.#state.getSession(sessionContext);\n\t\tif (!session?.jwt || (session.proof && Date.now() > session.expiresAt)) {\n\t\t\tawait this.#createSession({ network: sessionContext.client.network });\n\t\t}\n\n\t\tconst storedNativeSigner = await get<ExportedWebCryptoKeypair>(\n\t\t\t'ephemeralKeyPair',\n\t\t\tsessionContext.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 updatedSession = await this.#state.getSession(sessionContext);\n\t\tif (!updatedSession?.jwt) {\n\t\t\tthrow new Error('Failed to retrieve an active session.');\n\t\t}\n\n\t\tconst ephemeralKeypair = WebCryptoSigner.import(storedNativeSigner);\n\t\tconst proof = await this.#enokiClient.createZkLoginZkp({\n\t\t\tnetwork: sessionContext.client.network as EnokiNetwork,\n\t\t\tjwt: updatedSession.jwt,\n\t\t\tmaxEpoch: updatedSession.maxEpoch,\n\t\t\trandomness: updatedSession.randomness,\n\t\t\tephemeralPublicKey: ephemeralKeypair.getPublicKey(),\n\t\t});\n\n\t\tawait this.#state.setSession(sessionContext, { ...updatedSession, proof });\n\n\t\treturn new EnokiKeypair({\n\t\t\taddress: this.accounts[0].address,\n\t\t\tmaxEpoch: updatedSession.maxEpoch,\n\t\t\tephemeralKeypair,\n\t\t\tproof,\n\t\t});\n\t}\n\n\tasync #getSignerContext(chain?: IdentifierString) {\n\t\tconst sessionContext = chain ? this.#state.getSessionContext(chain.split(':')[1]) : null;\n\t\tif (!sessionContext) {\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\n\t\tconst keypair = await this.#getKeypair(sessionContext);\n\t\treturn { client: sessionContext.client, keypair };\n\t}\n\n\tasync #createSession({ network }: { network: Experimental_SuiClientTypes.Network }) {\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\n\t\tif (!popup) {\n\t\t\tthrow new Error('Failed to open popup');\n\t\t}\n\n\t\tconst sessionContext = this.#state.getSessionContext(network);\n\t\tpopup.location = await this.#createAuthorizationURL(sessionContext);\n\n\t\treturn await 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.#handleAuthCallback({ hash: popup.location.hash, sessionContext }).then(\n\t\t\t\t\t() => resolve(),\n\t\t\t\t\treject,\n\t\t\t\t);\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\t}\n\n\tasync #createAuthorizationURL(sessionContext: EnokiSessionContext) {\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: sessionContext.client.network as EnokiNetwork,\n\t\t\t\tephemeralPublicKey: ephemeralKeyPair.getPublicKey(),\n\t\t\t});\n\n\t\tconst extraParams =\n\t\t\ttypeof this.#extraParams === 'function' ? this.#extraParams() : this.#extraParams;\n\n\t\tconst params = new URLSearchParams({\n\t\t\t...extraParams,\n\t\t\tnonce,\n\t\t\tclient_id: this.#clientId,\n\t\t\tredirect_uri: this.#redirectUrl,\n\t\t\tresponse_type: 'id_token',\n\t\t\tscope: ['openid', ...(extraParams?.scope ? extraParams.scope.split(' ') : [])]\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 (this.#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\tcase 'facebook':\n\t\t\t\toauthUrl = `https://www.facebook.com/v17.0/dialog/oauth?${params}`;\n\t\t\t\tbreak;\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\tcase 'onefc':\n\t\t\t\toauthUrl = `https://login.onepassport.onefc.com/de3ee5c1-5644-4113-922d-e8336569a462/b2c_1a_prod_signupsignin_onesuizklogin/oauth2/v2.0/authorize?${params}`;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Invalid provider: ${this.#provider}`);\n\t\t}\n\n\t\tawait set('ephemeralKeyPair', ephemeralKeyPair.export(), sessionContext.idbStore);\n\t\tawait this.#state.setSession(sessionContext, {\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({\n\t\thash,\n\t\tsessionContext,\n\t}: {\n\t\thash: string;\n\t\tsessionContext: EnokiSessionContext;\n\t}) {\n\t\tconst params = new URLSearchParams(hash.startsWith('#') ? hash.slice(1) : hash);\n\t\tconst zkp = await this.#state.getSession(sessionContext);\n\n\t\tif (!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, publicKey } = await this.#enokiClient.getZkLogin({ jwt });\n\n\t\tthis.#state.zkLoginState.set({ address, publicKey });\n\t\tawait this.#state.setSession(sessionContext, { ...zkp, jwt });\n\n\t\treturn params.get('state');\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAA4B;AAC5B,mBAAqC;AAiBrC,6BAQO;AAEP,kBAAiB;AAKjB,qBAAiC;AAEjC,qBAA0B;AAE1B,uBAAgC;AAChC,wBAAyB;AAEzB,yBAA4B;AAE5B,0BAA6B;AAE7B,mBAAiC;AACjC,wBAAyB;AAhDzB;AAkDO,MAAM,YAA8B;AAAA,EA+E1C,YAAY;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,GAAuB;AA3FjB;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAmGA,yCAA6C,OAAO,EAAE,aAAa,OAAO,SAAS,OAAO,MAAM;AAC/F,cAAQ,eAAe;AAEvB,YAAM,EAAE,QAAQ,QAAQ,IAAI,MAAM,sBAAK,6CAAL,WAAuB;AACzD,YAAM,oBAAoB,gCAAY,KAAK,MAAM,YAAY,OAAO,CAAC;AACrE,YAAM,aAAa,QAAQ,aAAa;AAExC,UAAI,eAAe,QAAQ,SAAS;AACnC,cAAM,IAAI;AAAA,UACT,yBAAyB,QAAQ,OAAO,yDAAyD,UAAU;AAAA,QAC5G;AAAA,MACD;AAEA,wBAAkB,kBAAkB,UAAU;AAC9C,aAAO,QAAQ,gBAAgB,MAAM,kBAAkB,MAAM,EAAE,OAAO,CAAC,CAAC;AAAA,IACzE;AAEA,mDAAiE,OAAO;AAA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AAI,CAAC,KAAK,YAAY,CAAC,IAAI,YAAY;AACtC,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AAEA,QAAM,MAAM,OAAO,IAAI,UAAU;AACjC,MAAI,CAAC,KAAK;AACT,UAAM,IAAI,MAAM,kBAAkB;AAAA,EACnC;AAEA,gCAAU,GAAG;AAEb,QAAM,EAAE,SAAS,UAAU,IAAI,MAAM,mBAAK,cAAa,WAAW,EAAE,IAAI,CAAC;AAEzE,qBAAK,QAAO,aAAa,IAAI,EAAE,SAAS,UAAU,CAAC;AACnD,QAAM,mBAAK,QAAO,WAAW,gBAAgB,EAAE,GAAG,KAAK,IAAI,CAAC;AAE5D,SAAO,OAAO,IAAI,OAAO;AAC1B;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\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\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 type { EnokiWalletOptions, WalletEventsMap, EnokiSessionContext } from './types.js';\nimport type {\n\tEnokiGetMetadataFeature,\n\tEnokiGetMetadataMethod,\n\tEnokiGetSessionFeature,\n\tEnokiGetSessionMethod,\n} from './features.js';\nimport { EnokiGetMetadata, EnokiGetSession } from './features.js';\nimport type { Experimental_SuiClientTypes } from '@mysten/sui/experimental';\nimport { decodeJwt } from '@mysten/sui/zklogin';\nimport type { ExportedWebCryptoKeypair } from '@mysten/signers/webcrypto';\nimport { WebCryptoSigner } from '@mysten/signers/webcrypto';\nimport { get, set } from 'idb-keyval';\n\nimport { EnokiClient } from '../EnokiClient/index.js';\nimport type { EnokiNetwork } from '../EnokiClient/type.js';\nimport { EnokiKeypair } from '../EnokiKeypair.js';\n\nimport { EnokiWalletState } from './state.js';\nimport { allTasks } from 'nanostores';\n\nexport class EnokiWallet implements Wallet {\n\t#events: Emitter<WalletEventsMap>;\n\t#accounts: ReadonlyWalletAccount[];\n\t#name: string;\n\t#icon: Wallet['icon'];\n\t#enokiClient: EnokiClient;\n\t#state: EnokiWalletState;\n\t#provider: AuthProvider;\n\t#clientId: string;\n\t#redirectUrl: string;\n\t#extraParams: Record<string, string> | (() => Record<string, string>) | undefined;\n\t#getCurrentNetwork: () => Experimental_SuiClientTypes.Network;\n\t#windowFeatures?: string | (() => string);\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 [...this.#state.sessionContextByNetwork.keys()].map(\n\t\t\t(network) => `sui:${network}` as const,\n\t\t);\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\tEnokiGetSessionFeature {\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\t[EnokiGetSession]: {\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tgetSession: this.#getSession,\n\t\t\t},\n\t\t};\n\t}\n\n\tconstructor({\n\t\tname,\n\t\ticon,\n\t\tprovider,\n\t\tclientId,\n\t\tredirectUrl,\n\t\textraParams,\n\t\twindowFeatures,\n\t\tgetCurrentNetwork,\n\t\tapiKey,\n\t\tapiUrl,\n\t\tclients,\n\t}: EnokiWalletOptions) {\n\t\tthis.#events = mitt();\n\t\tthis.#name = name;\n\t\tthis.#icon = icon;\n\t\tthis.#enokiClient = new EnokiClient({ apiKey, apiUrl });\n\t\tthis.#state = new EnokiWalletState({ apiKey, clientId, clients });\n\t\tthis.#provider = provider;\n\t\tthis.#clientId = clientId;\n\t\tthis.#redirectUrl = redirectUrl || window.location.href.split('#')[0];\n\t\tthis.#extraParams = extraParams;\n\t\tthis.#windowFeatures = windowFeatures;\n\t\tthis.#getCurrentNetwork = getCurrentNetwork;\n\t\tthis.#accounts = [];\n\n\t\tthis.#state.zkLoginState.subscribe(() => {\n\t\t\tthis.#accounts = this.#getAuthorizedAccounts();\n\t\t\tthis.#events.emit('change', { accounts: this.#accounts });\n\t\t});\n\t}\n\n\t#signTransaction: SuiSignTransactionMethod = async ({ transaction, chain, account, signal }) => {\n\t\tsignal?.throwIfAborted();\n\n\t\tconst { client, keypair } = await this.#getSignerContext(chain);\n\t\tconst parsedTransaction = Transaction.from(await transaction.toJSON());\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 }));\n\t};\n\n\t#signAndExecuteTransaction: SuiSignAndExecuteTransactionMethod = async ({\n\t\ttransaction,\n\t\tchain,\n\t\taccount,\n\t\tsignal,\n\t}) => {\n\t\tsignal?.throwIfAborted();\n\n\t\tconst { client, keypair } = await this.#getSignerContext(chain);\n\t\tconst parsedTransaction = Transaction.from(await transaction.toJSON());\n\t\tconst bytes = await parsedTransaction.build({ client });\n\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\n\t\tconst result = await keypair.signAndExecuteTransaction({\n\t\t\ttransaction: parsedTransaction,\n\t\t\tclient,\n\t\t});\n\n\t\treturn {\n\t\t\tbytes: toBase64(bytes),\n\t\t\tsignature: result.signatures[0],\n\t\t\tdigest: result.digest,\n\t\t\teffects: toBase64(result.effects.bcs!),\n\t\t};\n\t};\n\n\t#signPersonalMessage: SuiSignPersonalMessageMethod = async ({ message, account, chain }) => {\n\t\tconst { keypair } = await this.#getSignerContext(chain);\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#getMetadata: EnokiGetMetadataMethod = () => {\n\t\treturn {\n\t\t\tprovider: this.#provider,\n\t\t};\n\t};\n\n\t#getSession: EnokiGetSessionMethod = async (input) => {\n\t\tconst sessionContext = this.#state.getSessionContext(\n\t\t\tinput?.network ?? this.#getCurrentNetwork(),\n\t\t);\n\t\treturn await this.#state.getSession(sessionContext);\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#connect: StandardConnectMethod = async (input) => {\n\t\t// NOTE: This is a hackfix for the old version of dApp Kit where auto-connection logic\n\t\t// only fires on initial mount of the WalletProvider component. Since hydrating the\n\t\t// zkLogin state from IndexedDB is an asynchronous process, we need to make sure it\n\t\t// is populated before the connect logic runs.\n\t\tawait allTasks();\n\n\t\tif (input?.silent || this.#accounts.length > 0) {\n\t\t\treturn { accounts: this.#accounts };\n\t\t}\n\n\t\tconst currentNetwork = this.#getCurrentNetwork();\n\t\tawait this.#createSession({ network: currentNetwork });\n\n\t\treturn { accounts: this.#accounts };\n\t};\n\n\t#disconnect: StandardDisconnectMethod = async () => {\n\t\tawait this.#state.logout();\n\t\tthis.#accounts = [];\n\t\tthis.#events.emit('change', { accounts: this.#accounts });\n\t};\n\n\t#getAuthorizedAccounts() {\n\t\tconst zkLoginState = this.#state.zkLoginState.get();\n\t\tif (zkLoginState) {\n\t\t\treturn [\n\t\t\t\tnew ReadonlyWalletAccount({\n\t\t\t\t\taddress: zkLoginState.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(zkLoginState.publicKey),\n\t\t\t\t}),\n\t\t\t];\n\t\t}\n\t\treturn [];\n\t}\n\n\tasync #getKeypair(sessionContext: EnokiSessionContext) {\n\t\tconst session = await this.#state.getSession(sessionContext);\n\t\tif (!session?.jwt || (session.proof && Date.now() > session.expiresAt)) {\n\t\t\tawait this.#createSession({ network: sessionContext.client.network });\n\t\t}\n\n\t\tconst storedNativeSigner = await get<ExportedWebCryptoKeypair>(\n\t\t\t'ephemeralKeyPair',\n\t\t\tsessionContext.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 updatedSession = await this.#state.getSession(sessionContext);\n\t\tif (!updatedSession?.jwt) {\n\t\t\tthrow new Error('Failed to retrieve an active session.');\n\t\t}\n\n\t\tconst ephemeralKeypair = WebCryptoSigner.import(storedNativeSigner);\n\t\tconst proof = await this.#enokiClient.createZkLoginZkp({\n\t\t\tnetwork: sessionContext.client.network as EnokiNetwork,\n\t\t\tjwt: updatedSession.jwt,\n\t\t\tmaxEpoch: updatedSession.maxEpoch,\n\t\t\trandomness: updatedSession.randomness,\n\t\t\tephemeralPublicKey: ephemeralKeypair.getPublicKey(),\n\t\t});\n\n\t\tawait this.#state.setSession(sessionContext, { ...updatedSession, proof });\n\n\t\treturn new EnokiKeypair({\n\t\t\taddress: this.accounts[0].address,\n\t\t\tmaxEpoch: updatedSession.maxEpoch,\n\t\t\tephemeralKeypair,\n\t\t\tproof,\n\t\t});\n\t}\n\n\tasync #getSignerContext(chain?: IdentifierString) {\n\t\tconst sessionContext = chain ? this.#state.getSessionContext(chain.split(':')[1]) : null;\n\t\tif (!sessionContext) {\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\n\t\tconst keypair = await this.#getKeypair(sessionContext);\n\t\treturn { client: sessionContext.client, keypair };\n\t}\n\n\tasync #createSession({ network }: { network: Experimental_SuiClientTypes.Network }) {\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\n\t\tif (!popup) {\n\t\t\tthrow new Error('Failed to open popup');\n\t\t}\n\n\t\tconst sessionContext = this.#state.getSessionContext(network);\n\t\tpopup.location = await this.#createAuthorizationURL(sessionContext);\n\n\t\treturn await 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.#handleAuthCallback({ hash: popup.location.hash, sessionContext }).then(\n\t\t\t\t\t() => resolve(),\n\t\t\t\t\treject,\n\t\t\t\t);\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\t}\n\n\tasync #createAuthorizationURL(sessionContext: EnokiSessionContext) {\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: sessionContext.client.network as EnokiNetwork,\n\t\t\t\tephemeralPublicKey: ephemeralKeyPair.getPublicKey(),\n\t\t\t});\n\n\t\tconst extraParams =\n\t\t\ttypeof this.#extraParams === 'function' ? this.#extraParams() : this.#extraParams;\n\n\t\tconst params = new URLSearchParams({\n\t\t\t...extraParams,\n\t\t\tnonce,\n\t\t\tclient_id: this.#clientId,\n\t\t\tredirect_uri: this.#redirectUrl,\n\t\t\tresponse_type: 'id_token',\n\t\t\tscope: ['openid', ...(extraParams?.scope ? extraParams.scope.split(' ') : [])]\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 (this.#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\tcase 'facebook':\n\t\t\t\toauthUrl = `https://www.facebook.com/v17.0/dialog/oauth?${params}`;\n\t\t\t\tbreak;\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\tcase 'onefc':\n\t\t\t\toauthUrl = `https://login.onepassport.onefc.com/de3ee5c1-5644-4113-922d-e8336569a462/b2c_1a_prod_signupsignin_onesuizklogin/oauth2/v2.0/authorize?${params}`;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Invalid provider: ${this.#provider}`);\n\t\t}\n\n\t\tawait set('ephemeralKeyPair', ephemeralKeyPair.export(), sessionContext.idbStore);\n\t\tawait this.#state.setSession(sessionContext, {\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({\n\t\thash,\n\t\tsessionContext,\n\t}: {\n\t\thash: string;\n\t\tsessionContext: EnokiSessionContext;\n\t}) {\n\t\tconst params = new URLSearchParams(hash.startsWith('#') ? hash.slice(1) : hash);\n\t\tconst zkp = await this.#state.getSession(sessionContext);\n\n\t\tif (!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, publicKey } = await this.#enokiClient.getZkLogin({ jwt });\n\n\t\tthis.#state.zkLoginState.set({ address, publicKey });\n\t\tawait this.#state.setSession(sessionContext, { ...zkp, jwt });\n\n\t\treturn params.get('state');\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAA4B;AAC5B,mBAAqC;AAiBrC,6BAQO;AAEP,kBAAiB;AAUjB,sBAAkD;AAElD,qBAA0B;AAE1B,uBAAgC;AAChC,wBAAyB;AAEzB,yBAA4B;AAE5B,0BAA6B;AAE7B,mBAAiC;AACjC,wBAAyB;AArDzB;AAuDO,MAAM,YAA8B;AAAA,EAoF1C,YAAY;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,GAAuB;AAhGjB;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAwGA,yCAA6C,OAAO,EAAE,aAAa,OAAO,SAAS,OAAO,MAAM;AAC/F,cAAQ,eAAe;AAEvB,YAAM,EAAE,QAAQ,QAAQ,IAAI,MAAM,sBAAK,6CAAL,WAAuB;AACzD,YAAM,oBAAoB,gCAAY,KAAK,MAAM,YAAY,OAAO,CAAC;AACrE,YAAM,aAAa,QAAQ,aAAa;AAExC,UAAI,eAAe,QAAQ,SAAS;AACnC,cAAM,IAAI;AAAA,UACT,yBAAyB,QAAQ,OAAO,yDAAyD,UAAU;AAAA,Q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,wBAAmB,eAAC;AAAA,EACzB;AAAA,EACA;AACD,GAGG;AACF,QAAM,SAAS,IAAI,gBAAgB,KAAK,WAAW,GAAG,IAAI,KAAK,MAAM,CAAC,IAAI,IAAI;AAC9E,QAAM,MAAM,MAAM,mBAAK,QAAO,WAAW,cAAc;AAEvD,MAAI,CAAC,KAAK,YAAY,CAAC,IAAI,YAAY;AACtC,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AAEA,QAAM,MAAM,OAAO,IAAI,UAAU;AACjC,MAAI,CAAC,KAAK;AACT,UAAM,IAAI,MAAM,kBAAkB;AAAA,EACnC;AAEA,gCAAU,GAAG;AAEb,QAAM,EAAE,SAAS,UAAU,IAAI,MAAM,mBAAK,cAAa,WAAW,EAAE,IAAI,CAAC;AAEzE,qBAAK,QAAO,aAAa,IAAI,EAAE,SAAS,UAAU,CAAC;AACnD,QAAM,mBAAK,QAAO,WAAW,gBAAgB,EAAE,GAAG,KAAK,IAAI,CAAC;AAE5D,SAAO,OAAO,IAAI,OAAO;AAC1B;",
6
6
  "names": ["mitt"]
7
7
  }
@@ -7,6 +7,6 @@ export { EnokiKeypair, EnokiPublicKey } from './EnokiKeypair.js';
7
7
  export type { EnokiWallet } from './wallet/wallet.js';
8
8
  export { registerEnokiWallets } from './wallet/register.js';
9
9
  export { enokiWalletsInitializer } from './wallet/initializer.js';
10
- export { isEnokiWallet, isGoogleWallet, isTwitchWallet, isFacebookWallet, getWalletMetadata, } from './wallet/utils.js';
10
+ export { isEnokiWallet, isGoogleWallet, isTwitchWallet, isFacebookWallet, getWalletMetadata, getSession, } from './wallet/utils.js';
11
11
  export { type RegisterEnokiWalletsOptions } from './wallet/types.js';
12
12
  export { isEnokiNetwork } from './utils.js';
package/dist/esm/index.js CHANGED
@@ -14,7 +14,8 @@ import {
14
14
  isGoogleWallet,
15
15
  isTwitchWallet,
16
16
  isFacebookWallet,
17
- getWalletMetadata
17
+ getWalletMetadata,
18
+ getSession
18
19
  } from "./wallet/utils.js";
19
20
  import { isEnokiNetwork } from "./utils.js";
20
21
  export {
@@ -28,6 +29,7 @@ export {
28
29
  createLocalStorage,
29
30
  createSessionStorage,
30
31
  enokiWalletsInitializer,
32
+ getSession,
31
33
  getWalletMetadata,
32
34
  isEnokiNetwork,
33
35
  isEnokiWallet,
@@ -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 type { EnokiWallet } from './wallet/wallet.js';\nexport { registerEnokiWallets } from './wallet/register.js';\nexport { enokiWalletsInitializer } from './wallet/initializer.js';\n\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;AAG7C,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AAExC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAGP,SAAS,sBAAsB;",
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 type { EnokiWallet } from './wallet/wallet.js';\nexport { registerEnokiWallets } from './wallet/register.js';\nexport { enokiWalletsInitializer } from './wallet/initializer.js';\n\nexport {\n\tisEnokiWallet,\n\tisGoogleWallet,\n\tisTwitchWallet,\n\tisFacebookWallet,\n\tgetWalletMetadata,\n\tgetSession,\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;AAG7C,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AAExC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAGP,SAAS,sBAAsB;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,50 @@
1
+ import type { AuthProvider, EnokiNetwork } from '../EnokiClient/type.js';
2
+ import type { ZkLoginSession } from './types.js';
3
+ /** Name of the feature for retrieving basic wallet metadata. */
4
+ export declare const EnokiGetMetadata = "enoki:getMetadata";
5
+ /** The latest API version of the getMetadata 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: EnokiGetMetadataVersion;
15
+ getMetadata: EnokiGetMetadataMethod;
16
+ };
17
+ };
18
+ export type EnokiGetMetadataMethod = (input?: EnokiGetMetadataInput) => EnokiGetMetadataOutput;
19
+ /** Input for retrieving metadata about the wallet. */
20
+ export type EnokiGetMetadataInput = void;
21
+ /** Output of retrieving metadata about the wallet. */
22
+ export type EnokiGetMetadataOutput = {
23
+ /** The social provider for the wallet. */
24
+ provider: AuthProvider;
25
+ };
26
+ /** Name of the feature for retrieving the Enoki session. */
27
+ export declare const EnokiGetSession = "enoki:getSession";
28
+ /** The latest API version of the getSession API. */
29
+ export type EnokiGetSessionVersion = '1.0.0';
30
+ /**
31
+ * A Wallet Standard feature for retreiving the zkLogin session from the wallet.
32
+ */
33
+ export type EnokiGetSessionFeature = {
34
+ /** Namespace for the feature. */
35
+ [EnokiGetSession]: {
36
+ /** Version of the feature API. */
37
+ version: EnokiGetSessionVersion;
38
+ getSession: EnokiGetSessionMethod;
39
+ };
40
+ };
41
+ export type EnokiGetSessionMethod = (input?: EnokiGetSessionInput) => Promise<EnokiGetSessionOutput>;
42
+ /** Input for retrieving the session from the wallet. */
43
+ export type EnokiGetSessionInput = {
44
+ /**
45
+ * The network to retrieve session data for. Defaults to the active network.
46
+ **/
47
+ network?: EnokiNetwork;
48
+ };
49
+ /** Output of retrieving the Enoki session. */
50
+ export type EnokiGetSessionOutput = ZkLoginSession | null;
@@ -0,0 +1,7 @@
1
+ const EnokiGetMetadata = "enoki:getMetadata";
2
+ const EnokiGetSession = "enoki:getSession";
3
+ export {
4
+ EnokiGetMetadata,
5
+ EnokiGetSession
6
+ };
7
+ //# sourceMappingURL=features.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/wallet/features.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { AuthProvider, EnokiNetwork } from '../EnokiClient/type.js';\nimport type { ZkLoginSession } from './types.js';\n\n/** Name of the feature for retrieving basic wallet metadata. */\nexport const EnokiGetMetadata = 'enoki:getMetadata';\n\n/** The latest API version of the getMetadata 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: EnokiGetMetadataVersion;\n\t\tgetMetadata: EnokiGetMetadataMethod;\n\t};\n};\n\nexport type EnokiGetMetadataMethod = (input?: EnokiGetMetadataInput) => EnokiGetMetadataOutput;\n\n/** Input for retrieving metadata about the wallet. */\nexport type EnokiGetMetadataInput = void;\n\n/** Output of retrieving metadata about the wallet. */\nexport type EnokiGetMetadataOutput = {\n\t/** The social provider for the wallet. */\n\tprovider: AuthProvider;\n};\n\n/** Name of the feature for retrieving the Enoki session. */\nexport const EnokiGetSession = 'enoki:getSession';\n\n/** The latest API version of the getSession API. */\nexport type EnokiGetSessionVersion = '1.0.0';\n\n/**\n * A Wallet Standard feature for retreiving the zkLogin session from the wallet.\n */\nexport type EnokiGetSessionFeature = {\n\t/** Namespace for the feature. */\n\t[EnokiGetSession]: {\n\t\t/** Version of the feature API. */\n\t\tversion: EnokiGetSessionVersion;\n\t\tgetSession: EnokiGetSessionMethod;\n\t};\n};\n\nexport type EnokiGetSessionMethod = (\n\tinput?: EnokiGetSessionInput,\n) => Promise<EnokiGetSessionOutput>;\n\n/** Input for retrieving the session from the wallet. */\nexport type EnokiGetSessionInput = {\n\t/**\n\t * The network to retrieve session data for. Defaults to the active network.\n\t **/\n\tnetwork?: EnokiNetwork;\n};\n\n/** Output of retrieving the Enoki session. */\nexport type EnokiGetSessionOutput = ZkLoginSession | null;\n"],
5
+ "mappings": "AAOO,MAAM,mBAAmB;AA6BzB,MAAM,kBAAkB;",
6
+ "names": []
7
+ }
@@ -1,9 +1,11 @@
1
1
  import type { Wallet } from '@mysten/wallet-standard';
2
2
  import type { UiWallet } from '@wallet-standard/ui';
3
3
  import type { EnokiWallet } from './wallet.js';
4
+ import type { EnokiGetSessionInput } from './features.js';
4
5
  export declare function isEnokiWallet(wallet: UiWallet): boolean;
5
6
  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 getWalletMetadata(wallet: Wallet | UiWallet): import("./features.js").EnokiGetMetadataOutput | null;
8
+ export declare function getSession(wallet: Wallet | UiWallet, input?: EnokiGetSessionInput): Promise<import("./features.js").EnokiGetSessionOutput>;
7
9
  export declare function isGoogleWallet(wallet: Wallet | UiWallet): boolean;
8
10
  export declare function isTwitchWallet(wallet: Wallet | UiWallet): boolean;
9
11
  export declare function isFacebookWallet(wallet: Wallet | UiWallet): boolean;
@@ -1,5 +1,5 @@
1
1
  import { getWalletFeature } from "@wallet-standard/ui";
2
- import { EnokiGetMetadata } from "./feature.js";
2
+ import { EnokiGetMetadata, EnokiGetSession } from "./features.js";
3
3
  function isEnokiWallet(wallet) {
4
4
  if (isWalletHandle(wallet)) {
5
5
  return wallet.features.includes(EnokiGetMetadata);
@@ -23,6 +23,23 @@ function getWalletMetadata(wallet) {
23
23
  }
24
24
  return null;
25
25
  }
26
+ async function getSession(wallet, input) {
27
+ if (isWalletHandle(wallet)) {
28
+ try {
29
+ const { getSession: getSession2 } = getWalletFeature(
30
+ wallet,
31
+ EnokiGetSession
32
+ );
33
+ return await getSession2(input);
34
+ } catch (error) {
35
+ return null;
36
+ }
37
+ } else if (EnokiGetSession in wallet.features) {
38
+ const walletWithFeature = wallet;
39
+ return await walletWithFeature.features[EnokiGetSession].getSession(input);
40
+ }
41
+ return null;
42
+ }
26
43
  function isGoogleWallet(wallet) {
27
44
  return getWalletMetadata(wallet)?.provider === "google";
28
45
  }
@@ -36,6 +53,7 @@ function isWalletHandle(wallet) {
36
53
  return Array.isArray(wallet.features);
37
54
  }
38
55
  export {
56
+ getSession,
39
57
  getWalletMetadata,
40
58
  isEnokiWallet,
41
59
  isFacebookWallet,