@openfort/openfort-js 0.8.29 → 0.8.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/cjs/packages/internal/openapi-clients/dist/index.js +1 -0
- package/dist/cjs/sdk/src/authManager.js +1 -0
- package/dist/cjs/sdk/src/chains/index.js +1 -0
- package/dist/cjs/sdk/src/config/config.js +1 -0
- package/dist/cjs/sdk/src/configuration/account.js +1 -0
- package/dist/cjs/sdk/src/configuration/authentication.js +1 -0
- package/dist/cjs/sdk/src/configuration/configuration.js +1 -0
- package/dist/cjs/sdk/src/configuration/recovery.js +1 -0
- package/dist/cjs/sdk/src/configuration/session.js +1 -0
- package/dist/cjs/sdk/src/crypto/key-pair.js +1 -0
- package/dist/cjs/sdk/src/errors/openfortError.js +1 -0
- package/dist/cjs/sdk/src/evm/JsonRpcError.js +1 -0
- package/dist/cjs/sdk/src/evm/addEthereumChain.js +1 -0
- package/dist/cjs/sdk/src/evm/estimateGas.js +1 -0
- package/dist/cjs/sdk/src/evm/evmProvider.js +1 -0
- package/dist/cjs/sdk/src/evm/getCallsStatus.js +1 -0
- package/dist/cjs/sdk/src/evm/personalSign.js +1 -0
- package/dist/cjs/sdk/src/evm/provider/eip6963.js +1 -0
- package/dist/cjs/sdk/src/evm/registerSession.js +1 -0
- package/dist/cjs/sdk/src/evm/revokeSession.js +1 -0
- package/dist/cjs/sdk/src/evm/sendCalls.js +1 -0
- package/dist/cjs/sdk/src/evm/signTypedDataV4.js +1 -0
- package/dist/cjs/sdk/src/evm/types.js +1 -0
- package/dist/cjs/sdk/src/evm/walletHelpers.js +1 -0
- package/dist/cjs/sdk/src/iframe/iframeManager.js +1 -0
- package/dist/cjs/sdk/src/iframe/types.js +1 -0
- package/dist/cjs/sdk/src/index.js +1 -0
- package/dist/cjs/sdk/src/manager/signer.js +1 -0
- package/dist/cjs/sdk/src/openfort.js +1 -0
- package/dist/cjs/sdk/src/signer/embedded.js +1 -0
- package/dist/cjs/sdk/src/signer/session.js +1 -0
- package/dist/cjs/sdk/src/storage/istorage.js +1 -0
- package/dist/cjs/sdk/src/storage/localStorage.js +1 -0
- package/dist/cjs/sdk/src/types.js +1 -0
- package/dist/cjs/sdk/src/utils/deviceCredentialsManager.js +1 -0
- package/dist/cjs/sdk/src/utils/helpers.js +1 -0
- package/dist/cjs/sdk/src/utils/typedEventEmitter.js +1 -0
- package/dist/cjs/sdk/src/version.js +1 -0
- package/dist/index.d.ts +8 -43
- package/dist/packages/internal/openapi-clients/dist/index.js +1 -0
- package/dist/sdk/src/authManager.js +1 -0
- package/dist/sdk/src/chains/index.js +1 -0
- package/dist/sdk/src/config/config.js +1 -0
- package/dist/sdk/src/configuration/account.js +1 -0
- package/dist/sdk/src/configuration/authentication.js +1 -0
- package/dist/sdk/src/configuration/configuration.js +1 -0
- package/dist/sdk/src/configuration/recovery.js +1 -0
- package/dist/sdk/src/configuration/session.js +1 -0
- package/dist/sdk/src/crypto/key-pair.js +1 -0
- package/dist/sdk/src/errors/openfortError.js +1 -0
- package/dist/sdk/src/evm/JsonRpcError.js +1 -0
- package/dist/sdk/src/evm/addEthereumChain.js +1 -0
- package/dist/sdk/src/evm/estimateGas.js +1 -0
- package/dist/sdk/src/evm/evmProvider.js +1 -0
- package/dist/sdk/src/evm/getCallsStatus.js +1 -0
- package/dist/sdk/src/evm/personalSign.js +1 -0
- package/dist/sdk/src/evm/provider/eip6963.js +1 -0
- package/dist/sdk/src/evm/registerSession.js +1 -0
- package/dist/sdk/src/evm/revokeSession.js +1 -0
- package/dist/sdk/src/evm/sendCalls.js +1 -0
- package/dist/sdk/src/evm/signTypedDataV4.js +1 -0
- package/dist/sdk/src/evm/types.js +1 -0
- package/dist/sdk/src/evm/walletHelpers.js +1 -0
- package/dist/sdk/src/iframe/iframeManager.js +1 -0
- package/dist/sdk/src/iframe/types.js +1 -0
- package/dist/sdk/src/index.js +1 -0
- package/dist/sdk/src/manager/signer.js +1 -0
- package/dist/sdk/src/openfort.js +1 -0
- package/dist/sdk/src/signer/embedded.js +1 -0
- package/dist/sdk/src/signer/session.js +1 -0
- package/dist/sdk/src/storage/istorage.js +1 -0
- package/dist/sdk/src/storage/localStorage.js +1 -0
- package/dist/sdk/src/types.js +1 -0
- package/dist/sdk/src/utils/deviceCredentialsManager.js +1 -0
- package/dist/sdk/src/utils/helpers.js +1 -0
- package/dist/sdk/src/utils/typedEventEmitter.js +1 -0
- package/dist/sdk/src/version.js +1 -0
- package/package.json +20 -18
- package/dist/index.cjs +0 -7970
- package/dist/index.js +0 -7939
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<h4>
|
|
3
|
-
<a href="https://www.openfort.
|
|
3
|
+
<a href="https://www.openfort.io/">
|
|
4
4
|
Website
|
|
5
5
|
</a>
|
|
6
6
|
<span> | </span>
|
|
7
|
-
<a href="https://www.openfort.
|
|
7
|
+
<a href="https://www.openfort.io/docs">
|
|
8
8
|
Documentation
|
|
9
9
|
</a>
|
|
10
10
|
<span> | </span>
|
|
11
|
-
<a href="https://www.openfort.
|
|
11
|
+
<a href="https://www.openfort.io/docs/reference/api/authentication">
|
|
12
12
|
API Docs
|
|
13
13
|
</a>
|
|
14
14
|
<span> | </span>
|
|
15
|
-
<a href="https://x.com/
|
|
15
|
+
<a href="https://x.com/openfort_hq">
|
|
16
16
|
X
|
|
17
17
|
</a>
|
|
18
18
|
</h4>
|
|
@@ -48,7 +48,7 @@ The Session Signer allows you to use external signing keys, without needing to p
|
|
|
48
48
|
```typescript
|
|
49
49
|
const sessionKey = sdk.configureSessionKey();
|
|
50
50
|
```
|
|
51
|
-
- **Register Key and Send Signature Session Request**: If `sessionKey.isRegistered` boolean is false, register the key from the backend. Refer to the documentation for [session keys](https://www.openfort.
|
|
51
|
+
- **Register Key and Send Signature Session Request**: If `sessionKey.isRegistered` boolean is false, register the key from the backend. Refer to the documentation for [session keys](https://www.openfort.io/docs/guides/javascript/smart-wallet/advanced/session-keys).
|
|
52
52
|
- **Send Signature Transaction Intent Request**: When calling sendSignatureTransactionIntentRequest, pass the transaction intent ID and the user operation hash. The session signer will handle the signing.
|
|
53
53
|
|
|
54
54
|
### 2. External Sign
|
|
@@ -62,7 +62,7 @@ const response = await sdk.sendSignatureTransactionIntentRequest("tin_xxxx", '0x
|
|
|
62
62
|
|
|
63
63
|
### 3. Embedded Signer
|
|
64
64
|
|
|
65
|
-
The Embedded Signer uses SSS to manage the private key on the client side. To learn more, visit our [security documentation](https://www.openfort.
|
|
65
|
+
The Embedded Signer uses SSS to manage the private key on the client side. To learn more, visit our [security documentation](https://www.openfort.io/docs/security).
|
|
66
66
|
- **Login and Configure the Embedded Signer**: First, ensure the user is logged in, using `LoginWithEmailPassword`, `AuthenticateWithOAuth` or if not registred `SignUpWithEmailPassword`. Then call `ConfigureEmbeddedSigner`.
|
|
67
67
|
```typescript
|
|
68
68
|
const shieldAuth: ShieldAuthentication = {
|
|
@@ -75,7 +75,7 @@ The Embedded Signer uses SSS to manage the private key on the client side. To le
|
|
|
75
75
|
// using automatic recovery
|
|
76
76
|
await sdk.configureEmbeddedSigner(chainId, shieldAuth);
|
|
77
77
|
```
|
|
78
|
-
For now the only two recovery method available are the `PasswordRecovery` and `AutomaticRecovery`. Learn more about the [recovery methods](https://www.openfort.
|
|
78
|
+
For now the only two recovery method available are the `PasswordRecovery` and `AutomaticRecovery`. Learn more about the [recovery methods](https://www.openfort.io/docs/guides/javascript/embedded-signer/recovery).
|
|
79
79
|
- **Send Signature Transaction Intent Request**: Similar to the session signer, pass the transaction intent ID and the user operation hash. The embedded signer reconstructs the key and signs the transaction.
|
|
80
80
|
```typescript
|
|
81
81
|
const response = await sdk.sendSignatureTransactionIntentRequest("transactionIntentId", "userOp");
|
|
@@ -86,7 +86,7 @@ const response = await sdk.sendSignatureTransactionIntentRequest("transactionInt
|
|
|
86
86
|
- [Next.js application with non-custodial signer](https://github.com/openfort-xyz/samples/tree/main/rainbow-ssv-nextjs)
|
|
87
87
|
- [Next.js application with custodial signer and social login](https://github.com/openfort-xyz/samples/tree/main/ssv-social-nextjs)
|
|
88
88
|
|
|
89
|
-
[next-action]: https://www.openfort.
|
|
89
|
+
[next-action]: https://www.openfort.io/docs/api/transaction_intents#the-transaction-intent-object
|
|
90
90
|
|
|
91
91
|
<!--
|
|
92
92
|
# vim: set tw=79:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("axios");const t="https://api.openfort.xyz".replace(/\/+$/,"");class n{basePath;axios;configuration;constructor(n,s=t,a=e){this.basePath=s,this.axios=a,n&&(this.configuration=n,this.basePath=n.basePath||this.basePath)}}class s extends Error{field;constructor(e,t){super(t),this.field=e,this.name="RequiredError"}}const a="https://example.com",i=function(e,t,n){if(null==n)throw new s(t,`Required parameter ${t} was null or undefined when calling ${e}.`)},o=async function(e,t){if(t&&t.accessToken){const n="function"==typeof t.accessToken?await t.accessToken():await t.accessToken;e.Authorization="Bearer "+n}};function r(e,t,n=""){null!=t&&("object"==typeof t?Array.isArray(t)?t.forEach((t=>r(e,t,n))):Object.keys(t).forEach((s=>r(e,t[s],`${n}${""!==n?".":""}${s}`))):e.has(n)?e.append(n,t):e.set(n,t))}const c=function(e,...t){const n=new URLSearchParams(e.search);r(n,t),e.search=n.toString()},h=function(e,t,n){const s="string"!=typeof e;return(s&&n&&n.isJsonMime?n.isJsonMime(t.headers["Content-Type"]):s)?JSON.stringify(void 0!==e?e:{}):e||""},u=function(e){return e.pathname+e.search+e.hash},d=function(e,t,n,s){return(a=t,i=n)=>{const o={...e.options,url:(s?.basePath||a.defaults.baseURL||i)+e.url};return a.request(o)}},l=function(n){const s=function(e){return{cancelTransferOwnership:async(t,n,s={})=>{i("cancelTransferOwnership","id",t),i("cancelTransferOwnership","cancelTransferOwnershipRequest",n);const r="/v1/accounts/{id}/cancel_transfer_ownership".replace("{id}",encodeURIComponent(String(t))),d=new URL(r,a);let l;e&&(l=e.baseOptions);const p={method:"POST",...l,...s},y={};await o(y,e),y["Content-Type"]="application/json",c(d,{});let w=l&&l.headers?l.headers:{};return p.headers={...y,...w,...s.headers},p.data=h(n,p,e),{url:u(d),options:p}},completeRecovery:async(t,n,s={})=>{i("completeRecovery","id",t),i("completeRecovery","completeRecoveryRequest",n);const r="/v1/accounts/{id}/complete_recovery".replace("{id}",encodeURIComponent(String(t))),d=new URL(r,a);let l;e&&(l=e.baseOptions);const p={method:"POST",...l,...s},y={};await o(y,e),y["Content-Type"]="application/json",c(d,{});let w=l&&l.headers?l.headers:{};return p.headers={...y,...w,...s.headers},p.data=h(n,p,e),{url:u(d),options:p}},createAccount:async(t,n={})=>{i("createAccount","createAccountRequest",t);const s=new URL("/v1/accounts",a);let r;e&&(r=e.baseOptions);const d={method:"POST",...r,...n},l={};await o(l,e),l["Content-Type"]="application/json",c(s,{});let p=r&&r.headers?r.headers:{};return d.headers={...l,...p,...n.headers},d.data=h(t,d,e),{url:u(s),options:d}},deployAccount:async(t,n,s={})=>{i("deployAccount","id",t),i("deployAccount","deployRequest",n);const r="/v1/accounts/{id}/deploy".replace("{id}",encodeURIComponent(String(t))),d=new URL(r,a);let l;e&&(l=e.baseOptions);const p={method:"POST",...l,...s},y={};await o(y,e),y["Content-Type"]="application/json",c(d,{});let w=l&&l.headers?l.headers:{};return p.headers={...y,...w,...s.headers},p.data=h(n,p,e),{url:u(d),options:p}},disableAccount:async(t,n={})=>{i("disableAccount","id",t);const s="/v1/accounts/{id}/disable".replace("{id}",encodeURIComponent(String(t))),r=new URL(s,a);let h;e&&(h=e.baseOptions);const d={method:"POST",...h,...n},l={};await o(l,e),c(r,{});let p=h&&h.headers?h.headers:{};return d.headers={...l,...p,...n.headers},{url:u(r),options:d}},getAccount:async(t,n,s={})=>{i("getAccount","id",t);const r="/v1/accounts/{id}".replace("{id}",encodeURIComponent(String(t))),h=new URL(r,a);let d;e&&(d=e.baseOptions);const l={method:"GET",...d,...s},p={},y={};await o(p,e),n&&(y.expand=n),c(h,y);let w=d&&d.headers?d.headers:{};return l.headers={...p,...w,...s.headers},{url:u(h),options:l}},getAccounts:async(t,n,s,r,h,d={})=>{i("getAccounts","player",t);const l=new URL("/v1/accounts",a);let p;e&&(p=e.baseOptions);const y={method:"GET",...p,...d},w={},g={};await o(w,e),void 0!==n&&(g.limit=n),void 0!==s&&(g.skip=s),void 0!==r&&(g.order=r),h&&(g.expand=h),void 0!==t&&(g.player=t),c(l,g);let m=p&&p.headers?p.headers:{};return y.headers={...w,...m,...d.headers},{url:u(l),options:y}},requestTransferOwnership:async(t,n,s={})=>{i("requestTransferOwnership","id",t),i("requestTransferOwnership","transferOwnershipRequest",n);const r="/v1/accounts/{id}/request_transfer_ownership".replace("{id}",encodeURIComponent(String(t))),d=new URL(r,a);let l;e&&(l=e.baseOptions);const p={method:"POST",...l,...s},y={};await o(y,e),y["Content-Type"]="application/json",c(d,{});let w=l&&l.headers?l.headers:{};return p.headers={...y,...w,...s.headers},p.data=h(n,p,e),{url:u(d),options:p}},signPayload:async(t,n,s={})=>{i("signPayload","id",t),i("signPayload","signPayloadRequest",n);const r="/v1/accounts/{id}/sign_payload".replace("{id}",encodeURIComponent(String(t))),d=new URL(r,a);let l;e&&(l=e.baseOptions);const p={method:"POST",...l,...s},y={};await o(y,e),y["Content-Type"]="application/json",c(d,{});let w=l&&l.headers?l.headers:{};return p.headers={...y,...w,...s.headers},p.data=h(n,p,e),{url:u(d),options:p}},startRecovery:async(t,n,s={})=>{i("startRecovery","id",t),i("startRecovery","startRecoveryRequest",n);const r="/v1/accounts/{id}/start_recovery".replace("{id}",encodeURIComponent(String(t))),d=new URL(r,a);let l;e&&(l=e.baseOptions);const p={method:"POST",...l,...s},y={};await o(y,e),y["Content-Type"]="application/json",c(d,{});let w=l&&l.headers?l.headers:{};return p.headers={...y,...w,...s.headers},p.data=h(n,p,e),{url:u(d),options:p}},syncAccount:async(t,n={})=>{i("syncAccount","id",t);const s="/v1/accounts/{id}/sync".replace("{id}",encodeURIComponent(String(t))),r=new URL(s,a);let h;e&&(h=e.baseOptions);const d={method:"POST",...h,...n},l={};await o(l,e),c(r,{});let p=h&&h.headers?h.headers:{};return d.headers={...l,...p,...n.headers},{url:u(r),options:d}}}}(n);return{async cancelTransferOwnership(a,i,o){const r=await s.cancelTransferOwnership(a,i,o);return d(r,e,t,n)},async completeRecovery(a,i,o){const r=await s.completeRecovery(a,i,o);return d(r,e,t,n)},async createAccount(a,i){const o=await s.createAccount(a,i);return d(o,e,t,n)},async deployAccount(a,i,o){const r=await s.deployAccount(a,i,o);return d(r,e,t,n)},async disableAccount(a,i){const o=await s.disableAccount(a,i);return d(o,e,t,n)},async getAccount(a,i,o){const r=await s.getAccount(a,i,o);return d(r,e,t,n)},async getAccounts(a,i,o,r,c,h){const u=await s.getAccounts(a,i,o,r,c,h);return d(u,e,t,n)},async requestTransferOwnership(a,i,o){const r=await s.requestTransferOwnership(a,i,o);return d(r,e,t,n)},async signPayload(a,i,o){const r=await s.signPayload(a,i,o);return d(r,e,t,n)},async startRecovery(a,i,o){const r=await s.startRecovery(a,i,o);return d(r,e,t,n)},async syncAccount(a,i){const o=await s.syncAccount(a,i);return d(o,e,t,n)}}};class p extends n{cancelTransferOwnership(e,t){return l(this.configuration).cancelTransferOwnership(e.id,e.cancelTransferOwnershipRequest,t).then((e=>e(this.axios,this.basePath)))}completeRecovery(e,t){return l(this.configuration).completeRecovery(e.id,e.completeRecoveryRequest,t).then((e=>e(this.axios,this.basePath)))}createAccount(e,t){return l(this.configuration).createAccount(e.createAccountRequest,t).then((e=>e(this.axios,this.basePath)))}deployAccount(e,t){return l(this.configuration).deployAccount(e.id,e.deployRequest,t).then((e=>e(this.axios,this.basePath)))}disableAccount(e,t){return l(this.configuration).disableAccount(e.id,t).then((e=>e(this.axios,this.basePath)))}getAccount(e,t){return l(this.configuration).getAccount(e.id,e.expand,t).then((e=>e(this.axios,this.basePath)))}getAccounts(e,t){return l(this.configuration).getAccounts(e.player,e.limit,e.skip,e.order,e.expand,t).then((e=>e(this.axios,this.basePath)))}requestTransferOwnership(e,t){return l(this.configuration).requestTransferOwnership(e.id,e.transferOwnershipRequest,t).then((e=>e(this.axios,this.basePath)))}signPayload(e,t){return l(this.configuration).signPayload(e.id,e.signPayloadRequest,t).then((e=>e(this.axios,this.basePath)))}startRecovery(e,t){return l(this.configuration).startRecovery(e.id,e.startRecoveryRequest,t).then((e=>e(this.axios,this.basePath)))}syncAccount(e,t){return l(this.configuration).syncAccount(e.id,t).then((e=>e(this.axios,this.basePath)))}}const y=function(n){const s=function(e){return{authenticateOAuth:async(t,n={})=>{i("authenticateOAuth","authenticateOAuthRequest",t);const s=new URL("/iam/v1/oauth/authenticate",a);let r;e&&(r=e.baseOptions);const d={method:"POST",...r,...n},l={};await o(l,e),l["Content-Type"]="application/json",c(s,{});let p=r&&r.headers?r.headers:{};return d.headers={...l,...p,...n.headers},d.data=h(t,d,e),{url:u(s),options:d}},authenticateSIWE:async(t,n={})=>{i("authenticateSIWE","sIWEAuthenticateRequest",t);const s=new URL("/iam/v1/siwe/authenticate",a);let r;e&&(r=e.baseOptions);const d={method:"POST",...r,...n},l={};await o(l,e),l["Content-Type"]="application/json",c(s,{});let p=r&&r.headers?r.headers:{};return d.headers={...l,...p,...n.headers},d.data=h(t,d,e),{url:u(s),options:d}},authorizeWithOAuthToken:async(t,n,s={})=>{i("authorizeWithOAuthToken","provider",t),i("authorizeWithOAuthToken","oAuthRequest",n);const r="/iam/v1/oauth/{provider}/authorize".replace("{provider}",encodeURIComponent(String(t))),d=new URL(r,a);let l;e&&(l=e.baseOptions);const p={method:"POST",...l,...s},y={};await o(y,e),await o(y,e),y["Content-Type"]="application/json",c(d,{});let w=l&&l.headers?l.headers:{};return p.headers={...y,...w,...s.headers},p.data=h(n,p,e),{url:u(d),options:p}},getJwks:async(t,n={})=>{i("getJwks","publishableKey",t);const s="/iam/v1/{publishable_key}/jwks.json".replace("{publishable_key}",encodeURIComponent(String(t))),o=new URL(s,a);let r;e&&(r=e.baseOptions);const h={method:"GET",...r,...n};c(o,{});let d=r&&r.headers?r.headers:{};return h.headers={...d,...n.headers},{url:u(o),options:h}},initOAuth:async(t,n,s={})=>{i("initOAuth","oAuthInitRequest",t);const r=new URL("/iam/v1/oauth/init",a);let d;e&&(d=e.baseOptions);const l={method:"POST",...d,...s},p={};await o(p,e),null!=n&&(p["x-game"]=String(n)),p["Content-Type"]="application/json",c(r,{});let y=d&&d.headers?d.headers:{};return l.headers={...p,...y,...s.headers},l.data=h(t,l,e),{url:u(r),options:l}},initSIWE:async(t,n,s={})=>{i("initSIWE","sIWERequest",t);const r=new URL("/iam/v1/siwe/init",a);let d;e&&(d=e.baseOptions);const l={method:"POST",...d,...s},p={};await o(p,e),null!=n&&(p["x-game"]=String(n)),p["Content-Type"]="application/json",c(r,{});let y=d&&d.headers?d.headers:{};return l.headers={...p,...y,...s.headers},l.data=h(t,l,e),{url:u(r),options:l}},linkEmail:async(t,n,s={})=>{i("linkEmail","loginRequest",t);const o=new URL("/iam/v1/password/link",a);let r;e&&(r=e.baseOptions);const d={method:"POST",...r,...s},l={};null!=n&&(l["x-game"]=String(n)),l["Content-Type"]="application/json",c(o,{});let p=r&&r.headers?r.headers:{};return d.headers={...l,...p,...s.headers},d.data=h(t,d,e),{url:u(o),options:d}},linkOAuth:async(t,n,s={})=>{i("linkOAuth","oAuthInitRequest",t);const o=new URL("/iam/v1/oauth/init_link",a);let r;e&&(r=e.baseOptions);const d={method:"POST",...r,...s},l={};null!=n&&(l["x-game"]=String(n)),l["Content-Type"]="application/json",c(o,{});let p=r&&r.headers?r.headers:{};return d.headers={...l,...p,...s.headers},d.data=h(t,d,e),{url:u(o),options:d}},linkSIWE:async(t,n={})=>{i("linkSIWE","sIWEAuthenticateRequest",t);const s=new URL("/iam/v1/siwe/link",a);let o;e&&(o=e.baseOptions);const r={method:"POST",...o,...n},d={"Content-Type":"application/json"};c(s,{});let l=o&&o.headers?o.headers:{};return r.headers={...d,...l,...n.headers},r.data=h(t,r,e),{url:u(s),options:r}},linkThirdParty:async(t,n,s={})=>{i("linkThirdParty","thirdPartyLinkRequest",t);const o=new URL("/iam/v1/oauth/link",a);let r;e&&(r=e.baseOptions);const d={method:"POST",...r,...s},l={};null!=n&&(l["x-game"]=String(n)),l["Content-Type"]="application/json",c(o,{});let p=r&&r.headers?r.headers:{};return d.headers={...l,...p,...s.headers},d.data=h(t,d,e),{url:u(o),options:d}},loginEmailPassword:async(t,n,s={})=>{i("loginEmailPassword","loginRequest",t);const r=new URL("/iam/v1/password/login",a);let d;e&&(d=e.baseOptions);const l={method:"POST",...d,...s},p={};await o(p,e),null!=n&&(p["x-game"]=String(n)),p["Content-Type"]="application/json",c(r,{});let y=d&&d.headers?d.headers:{};return l.headers={...p,...y,...s.headers},l.data=h(t,l,e),{url:u(r),options:l}},loginOIDC:async(t,n,s={})=>{i("loginOIDC","loginOIDCRequest",t);const r=new URL("/iam/v1/oidc/login",a);let d;e&&(d=e.baseOptions);const l={method:"POST",...d,...s},p={};await o(p,e),null!=n&&(p["x-game"]=String(n)),p["Content-Type"]="application/json",c(r,{});let y=d&&d.headers?d.headers:{};return l.headers={...p,...y,...s.headers},l.data=h(t,l,e),{url:u(r),options:l}},logout:async(t,n={})=>{i("logout","logoutRequest",t);const s=new URL("/iam/v1/sessions/logout",a);let o;e&&(o=e.baseOptions);const r={method:"POST",...o,...n},d={"Content-Type":"application/json"};c(s,{});let l=o&&o.headers?o.headers:{};return r.headers={...d,...l,...n.headers},r.data=h(t,r,e),{url:u(s),options:r}},me:async(t={})=>{const n=new URL("/iam/v1/me",a);let s;e&&(s=e.baseOptions);const i={method:"GET",...s,...t};c(n,{});let o=s&&s.headers?s.headers:{};return i.headers={...o,...t.headers},{url:u(n),options:i}},poolOAuth:async(t,n={})=>{i("poolOAuth","key",t);const s=new URL("/iam/v1/oauth/pool",a);let r;e&&(r=e.baseOptions);const h={method:"POST",...r,...n},d={},l={};await o(d,e),void 0!==t&&(l.key=t),c(s,l);let p=r&&r.headers?r.headers:{};return h.headers={...d,...p,...n.headers},{url:u(s),options:h}},refresh:async(t,n={})=>{i("refresh","refreshTokenRequest",t);const s=new URL("/iam/v1/sessions",a);let r;e&&(r=e.baseOptions);const d={method:"POST",...r,...n},l={};await o(l,e),l["Content-Type"]="application/json",c(s,{});let p=r&&r.headers?r.headers:{};return d.headers={...l,...p,...n.headers},d.data=h(t,d,e),{url:u(s),options:d}},registerGuest:async(t,n={})=>{const s=new URL("/iam/v1/guest",a);let i;e&&(i=e.baseOptions);const r={method:"POST",...i,...n},h={};await o(h,e),null!=t&&(h["x-game"]=String(t)),c(s,{});let d=i&&i.headers?i.headers:{};return r.headers={...h,...d,...n.headers},{url:u(s),options:r}},requestEmailVerification:async(t,n={})=>{i("requestEmailVerification","requestVerifyEmailRequest",t);const s=new URL("/iam/v1/password/request_email_verification",a);let r;e&&(r=e.baseOptions);const d={method:"POST",...r,...n},l={};await o(l,e),l["Content-Type"]="application/json",c(s,{});let p=r&&r.headers?r.headers:{};return d.headers={...l,...p,...n.headers},d.data=h(t,d,e),{url:u(s),options:d}},requestResetPassword:async(t,n={})=>{i("requestResetPassword","requestResetPasswordRequest",t);const s=new URL("/iam/v1/password/request_reset",a);let r;e&&(r=e.baseOptions);const d={method:"POST",...r,...n},l={};await o(l,e),l["Content-Type"]="application/json",c(s,{});let p=r&&r.headers?r.headers:{};return d.headers={...l,...p,...n.headers},d.data=h(t,d,e),{url:u(s),options:d}},resetPassword:async(t,n={})=>{i("resetPassword","resetPasswordRequest",t);const s=new URL("/iam/v1/password/reset",a);let r;e&&(r=e.baseOptions);const d={method:"POST",...r,...n},l={};await o(l,e),l["Content-Type"]="application/json",c(s,{});let p=r&&r.headers?r.headers:{};return d.headers={...l,...p,...n.headers},d.data=h(t,d,e),{url:u(s),options:d}},signupEmailPassword:async(t,n,s={})=>{i("signupEmailPassword","signupRequest",t);const r=new URL("/iam/v1/password/signup",a);let d;e&&(d=e.baseOptions);const l={method:"POST",...d,...s},p={};await o(p,e),null!=n&&(p["x-game"]=String(n)),p["Content-Type"]="application/json",c(r,{});let y=d&&d.headers?d.headers:{};return l.headers={...p,...y,...s.headers},l.data=h(t,l,e),{url:u(r),options:l}},thirdParty:async(t,n,s={})=>{i("thirdParty","thirdPartyOAuthRequest",t);const r=new URL("/iam/v1/oauth/third_party",a);let d;e&&(d=e.baseOptions);const l={method:"POST",...d,...s},p={};await o(p,e),null!=n&&(p["x-game"]=String(n)),p["Content-Type"]="application/json",c(r,{});let y=d&&d.headers?d.headers:{};return l.headers={...p,...y,...s.headers},l.data=h(t,l,e),{url:u(r),options:l}},unlinkEmail:async(t,n={})=>{i("unlinkEmail","unlinkEmailRequest",t);const s=new URL("/iam/v1/password/unlink",a);let o;e&&(o=e.baseOptions);const r={method:"POST",...o,...n},d={"Content-Type":"application/json"};c(s,{});let l=o&&o.headers?o.headers:{};return r.headers={...d,...l,...n.headers},r.data=h(t,r,e),{url:u(s),options:r}},unlinkOAuth:async(t,n={})=>{i("unlinkOAuth","unlinkOAuthRequest",t);const s=new URL("/iam/v1/oauth/unlink",a);let o;e&&(o=e.baseOptions);const r={method:"POST",...o,...n},d={"Content-Type":"application/json"};c(s,{});let l=o&&o.headers?o.headers:{};return r.headers={...d,...l,...n.headers},r.data=h(t,r,e),{url:u(s),options:r}},unlinkSIWE:async(t,n={})=>{i("unlinkSIWE","sIWERequest",t);const s=new URL("/iam/v1/siwe/unlink",a);let o;e&&(o=e.baseOptions);const r={method:"POST",...o,...n},d={"Content-Type":"application/json"};c(s,{});let l=o&&o.headers?o.headers:{};return r.headers={...d,...l,...n.headers},r.data=h(t,r,e),{url:u(s),options:r}},verifyEmail:async(t,n={})=>{i("verifyEmail","verifyEmailRequest",t);const s=new URL("/iam/v1/password/verify_email",a);let r;e&&(r=e.baseOptions);const d={method:"POST",...r,...n},l={};await o(l,e),l["Content-Type"]="application/json",c(s,{});let p=r&&r.headers?r.headers:{};return d.headers={...l,...p,...n.headers},d.data=h(t,d,e),{url:u(s),options:d}},verifyOAuth:async(t,n,s={})=>{i("verifyOAuth","provider",t),i("verifyOAuth","oAuthRequest",n);const r="/iam/v1/oauth/{provider}/verify".replace("{provider}",encodeURIComponent(String(t))),d=new URL(r,a);let l;e&&(l=e.baseOptions);const p={method:"POST",...l,...s},y={};await o(y,e),y["Content-Type"]="application/json",c(d,{});let w=l&&l.headers?l.headers:{};return p.headers={...y,...w,...s.headers},p.data=h(n,p,e),{url:u(d),options:p}},verifyOAuthToken:async(t,n={})=>{i("verifyOAuthToken","authenticateOAuthRequest",t);const s=new URL("/iam/v1/oauth/verify",a);let r;e&&(r=e.baseOptions);const d={method:"POST",...r,...n},l={};await o(l,e),l["Content-Type"]="application/json",c(s,{});let p=r&&r.headers?r.headers:{};return d.headers={...l,...p,...n.headers},d.data=h(t,d,e),{url:u(s),options:d}}}}(n);return{async authenticateOAuth(a,i){const o=await s.authenticateOAuth(a,i);return d(o,e,t,n)},async authenticateSIWE(a,i){const o=await s.authenticateSIWE(a,i);return d(o,e,t,n)},async authorizeWithOAuthToken(a,i,o){const r=await s.authorizeWithOAuthToken(a,i,o);return d(r,e,t,n)},async getJwks(a,i){const o=await s.getJwks(a,i);return d(o,e,t,n)},async initOAuth(a,i,o){const r=await s.initOAuth(a,i,o);return d(r,e,t,n)},async initSIWE(a,i,o){const r=await s.initSIWE(a,i,o);return d(r,e,t,n)},async linkEmail(a,i,o){const r=await s.linkEmail(a,i,o);return d(r,e,t,n)},async linkOAuth(a,i,o){const r=await s.linkOAuth(a,i,o);return d(r,e,t,n)},async linkSIWE(a,i){const o=await s.linkSIWE(a,i);return d(o,e,t,n)},async linkThirdParty(a,i,o){const r=await s.linkThirdParty(a,i,o);return d(r,e,t,n)},async loginEmailPassword(a,i,o){const r=await s.loginEmailPassword(a,i,o);return d(r,e,t,n)},async loginOIDC(a,i,o){const r=await s.loginOIDC(a,i,o);return d(r,e,t,n)},async logout(a,i){const o=await s.logout(a,i);return d(o,e,t,n)},async me(a){const i=await s.me(a);return d(i,e,t,n)},async poolOAuth(a,i){const o=await s.poolOAuth(a,i);return d(o,e,t,n)},async refresh(a,i){const o=await s.refresh(a,i);return d(o,e,t,n)},async registerGuest(a,i){const o=await s.registerGuest(a,i);return d(o,e,t,n)},async requestEmailVerification(a,i){const o=await s.requestEmailVerification(a,i);return d(o,e,t,n)},async requestResetPassword(a,i){const o=await s.requestResetPassword(a,i);return d(o,e,t,n)},async resetPassword(a,i){const o=await s.resetPassword(a,i);return d(o,e,t,n)},async signupEmailPassword(a,i,o){const r=await s.signupEmailPassword(a,i,o);return d(r,e,t,n)},async thirdParty(a,i,o){const r=await s.thirdParty(a,i,o);return d(r,e,t,n)},async unlinkEmail(a,i){const o=await s.unlinkEmail(a,i);return d(o,e,t,n)},async unlinkOAuth(a,i){const o=await s.unlinkOAuth(a,i);return d(o,e,t,n)},async unlinkSIWE(a,i){const o=await s.unlinkSIWE(a,i);return d(o,e,t,n)},async verifyEmail(a,i){const o=await s.verifyEmail(a,i);return d(o,e,t,n)},async verifyOAuth(a,i,o){const r=await s.verifyOAuth(a,i,o);return d(r,e,t,n)},async verifyOAuthToken(a,i){const o=await s.verifyOAuthToken(a,i);return d(o,e,t,n)}}};class w extends n{authenticateOAuth(e,t){return y(this.configuration).authenticateOAuth(e.authenticateOAuthRequest,t).then((e=>e(this.axios,this.basePath)))}authenticateSIWE(e,t){return y(this.configuration).authenticateSIWE(e.sIWEAuthenticateRequest,t).then((e=>e(this.axios,this.basePath)))}authorizeWithOAuthToken(e,t){return y(this.configuration).authorizeWithOAuthToken(e.provider,e.oAuthRequest,t).then((e=>e(this.axios,this.basePath)))}getJwks(e,t){return y(this.configuration).getJwks(e.publishableKey,t).then((e=>e(this.axios,this.basePath)))}initOAuth(e,t){return y(this.configuration).initOAuth(e.oAuthInitRequest,e.xGame,t).then((e=>e(this.axios,this.basePath)))}initSIWE(e,t){return y(this.configuration).initSIWE(e.sIWERequest,e.xGame,t).then((e=>e(this.axios,this.basePath)))}linkEmail(e,t){return y(this.configuration).linkEmail(e.loginRequest,e.xGame,t).then((e=>e(this.axios,this.basePath)))}linkOAuth(e,t){return y(this.configuration).linkOAuth(e.oAuthInitRequest,e.xGame,t).then((e=>e(this.axios,this.basePath)))}linkSIWE(e,t){return y(this.configuration).linkSIWE(e.sIWEAuthenticateRequest,t).then((e=>e(this.axios,this.basePath)))}linkThirdParty(e,t){return y(this.configuration).linkThirdParty(e.thirdPartyLinkRequest,e.xGame,t).then((e=>e(this.axios,this.basePath)))}loginEmailPassword(e,t){return y(this.configuration).loginEmailPassword(e.loginRequest,e.xGame,t).then((e=>e(this.axios,this.basePath)))}loginOIDC(e,t){return y(this.configuration).loginOIDC(e.loginOIDCRequest,e.xGame,t).then((e=>e(this.axios,this.basePath)))}logout(e,t){return y(this.configuration).logout(e.logoutRequest,t).then((e=>e(this.axios,this.basePath)))}me(e){return y(this.configuration).me(e).then((e=>e(this.axios,this.basePath)))}poolOAuth(e,t){return y(this.configuration).poolOAuth(e.key,t).then((e=>e(this.axios,this.basePath)))}refresh(e,t){return y(this.configuration).refresh(e.refreshTokenRequest,t).then((e=>e(this.axios,this.basePath)))}registerGuest(e={},t){return y(this.configuration).registerGuest(e.xGame,t).then((e=>e(this.axios,this.basePath)))}requestEmailVerification(e,t){return y(this.configuration).requestEmailVerification(e.requestVerifyEmailRequest,t).then((e=>e(this.axios,this.basePath)))}requestResetPassword(e,t){return y(this.configuration).requestResetPassword(e.requestResetPasswordRequest,t).then((e=>e(this.axios,this.basePath)))}resetPassword(e,t){return y(this.configuration).resetPassword(e.resetPasswordRequest,t).then((e=>e(this.axios,this.basePath)))}signupEmailPassword(e,t){return y(this.configuration).signupEmailPassword(e.signupRequest,e.xGame,t).then((e=>e(this.axios,this.basePath)))}thirdParty(e,t){return y(this.configuration).thirdParty(e.thirdPartyOAuthRequest,e.xGame,t).then((e=>e(this.axios,this.basePath)))}unlinkEmail(e,t){return y(this.configuration).unlinkEmail(e.unlinkEmailRequest,t).then((e=>e(this.axios,this.basePath)))}unlinkOAuth(e,t){return y(this.configuration).unlinkOAuth(e.unlinkOAuthRequest,t).then((e=>e(this.axios,this.basePath)))}unlinkSIWE(e,t){return y(this.configuration).unlinkSIWE(e.sIWERequest,t).then((e=>e(this.axios,this.basePath)))}verifyEmail(e,t){return y(this.configuration).verifyEmail(e.verifyEmailRequest,t).then((e=>e(this.axios,this.basePath)))}verifyOAuth(e,t){return y(this.configuration).verifyOAuth(e.provider,e.oAuthRequest,t).then((e=>e(this.axios,this.basePath)))}verifyOAuthToken(e,t){return y(this.configuration).verifyOAuthToken(e.authenticateOAuthRequest,t).then((e=>e(this.axios,this.basePath)))}}const g=function(n){const s=function(e){return{createSession:async(t,n,s={})=>{i("createSession","createSessionRequest",t);const r=new URL("/v1/sessions",a);let d;e&&(d=e.baseOptions);const l={method:"POST",...d,...s},p={};await o(p,e),null!=n&&(p["X-Behalf-Of-Project"]=String(n)),p["Content-Type"]="application/json",c(r,{});let y=d&&d.headers?d.headers:{};return l.headers={...p,...y,...s.headers},l.data=h(t,l,e),{url:u(r),options:l}},getPlayerSessions:async(t,n,s,r,h,d={})=>{i("getPlayerSessions","player",t);const l=new URL("/v1/sessions",a);let p;e&&(p=e.baseOptions);const y={method:"GET",...p,...d},w={},g={};await o(w,e),void 0!==n&&(g.limit=n),void 0!==s&&(g.skip=s),void 0!==r&&(g.order=r),void 0!==t&&(g.player=t),h&&(g.expand=h),c(l,g);let m=p&&p.headers?p.headers:{};return y.headers={...w,...m,...d.headers},{url:u(l),options:y}},getSession:async(t,n,s={})=>{i("getSession","id",t);const r="/v1/sessions/{id}".replace("{id}",encodeURIComponent(String(t))),h=new URL(r,a);let d;e&&(d=e.baseOptions);const l={method:"GET",...d,...s},p={},y={};await o(p,e),n&&(y.expand=n),c(h,y);let w=d&&d.headers?d.headers:{};return l.headers={...p,...w,...s.headers},{url:u(h),options:l}},revokeSession:async(t,n,s={})=>{i("revokeSession","revokeSessionRequest",t);const r=new URL("/v1/sessions/revoke",a);let d;e&&(d=e.baseOptions);const l={method:"POST",...d,...s},p={};await o(p,e),null!=n&&(p["X-Behalf-Of-Project"]=String(n)),p["Content-Type"]="application/json",c(r,{});let y=d&&d.headers?d.headers:{};return l.headers={...p,...y,...s.headers},l.data=h(t,l,e),{url:u(r),options:l}},signatureSession:async(t,n,s={})=>{i("signatureSession","id",t),i("signatureSession","signatureRequest",n);const r="/v1/sessions/{id}/signature".replace("{id}",encodeURIComponent(String(t))),d=new URL(r,a);let l;e&&(l=e.baseOptions);const p={method:"POST",...l,...s},y={};await o(y,e),await o(y,e),y["Content-Type"]="application/json",c(d,{});let w=l&&l.headers?l.headers:{};return p.headers={...y,...w,...s.headers},p.data=h(n,p,e),{url:u(d),options:p}}}}(n);return{async createSession(a,i,o){const r=await s.createSession(a,i,o);return d(r,e,t,n)},async getPlayerSessions(a,i,o,r,c,h){const u=await s.getPlayerSessions(a,i,o,r,c,h);return d(u,e,t,n)},async getSession(a,i,o){const r=await s.getSession(a,i,o);return d(r,e,t,n)},async revokeSession(a,i,o){const r=await s.revokeSession(a,i,o);return d(r,e,t,n)},async signatureSession(a,i,o){const r=await s.signatureSession(a,i,o);return d(r,e,t,n)}}};class m extends n{createSession(e,t){return g(this.configuration).createSession(e.createSessionRequest,e.xBehalfOfProject,t).then((e=>e(this.axios,this.basePath)))}getPlayerSessions(e,t){return g(this.configuration).getPlayerSessions(e.player,e.limit,e.skip,e.order,e.expand,t).then((e=>e(this.axios,this.basePath)))}getSession(e,t){return g(this.configuration).getSession(e.id,e.expand,t).then((e=>e(this.axios,this.basePath)))}revokeSession(e,t){return g(this.configuration).revokeSession(e.revokeSessionRequest,e.xBehalfOfProject,t).then((e=>e(this.axios,this.basePath)))}signatureSession(e,t){return g(this.configuration).signatureSession(e.id,e.signatureRequest,t).then((e=>e(this.axios,this.basePath)))}}const O=function(n){const s=function(e){return{createTransactionIntent:async(t,n,s={})=>{i("createTransactionIntent","createTransactionIntentRequest",t);const r=new URL("/v1/transaction_intents",a);let d;e&&(d=e.baseOptions);const l={method:"POST",...d,...s},p={};await o(p,e),null!=n&&(p["X-Behalf-Of-Project"]=String(n)),p["Content-Type"]="application/json",c(r,{});let y=d&&d.headers?d.headers:{};return l.headers={...p,...y,...s.headers},l.data=h(t,l,e),{url:u(r),options:l}},estimateTransactionIntentCost:async(t,n={})=>{i("estimateTransactionIntentCost","createTransactionIntentRequest",t);const s=new URL("/v1/transaction_intents/estimate_gas_cost",a);let r;e&&(r=e.baseOptions);const d={method:"POST",...r,...n},l={};await o(l,e),l["Content-Type"]="application/json",c(s,{});let p=r&&r.headers?r.headers:{};return d.headers={...l,...p,...n.headers},d.data=h(t,d,e),{url:u(s),options:d}},getTransactionIntent:async(t,n,s={})=>{i("getTransactionIntent","id",t);const r="/v1/transaction_intents/{id}".replace("{id}",encodeURIComponent(String(t))),h=new URL(r,a);let d;e&&(d=e.baseOptions);const l={method:"GET",...d,...s},p={},y={};await o(p,e),n&&(y.expand=n),c(h,y);let w=d&&d.headers?d.headers:{};return l.headers={...p,...w,...s.headers},{url:u(h),options:l}},getTransactionIntents:async(t,n,s,i,r,h,d,l,p,y={})=>{const w=new URL("/v1/transaction_intents",a);let g;e&&(g=e.baseOptions);const m={method:"GET",...g,...y},O={},R={};await o(O,e),void 0!==t&&(R.limit=t),void 0!==n&&(R.skip=n),void 0!==s&&(R.order=s),i&&(R.expand=i),void 0!==r&&(R.chainId=r),h&&(R.account=h),d&&(R.player=d),void 0!==l&&(R.status=l),p&&(R.policy=p),c(w,R);let P=g&&g.headers?g.headers:{};return m.headers={...O,...P,...y.headers},{url:u(w),options:m}},signature:async(t,n,s={})=>{i("signature","id",t),i("signature","signatureRequest",n);const r="/v1/transaction_intents/{id}/signature".replace("{id}",encodeURIComponent(String(t))),d=new URL(r,a);let l;e&&(l=e.baseOptions);const p={method:"POST",...l,...s},y={};await o(y,e),await o(y,e),y["Content-Type"]="application/json",c(d,{});let w=l&&l.headers?l.headers:{};return p.headers={...y,...w,...s.headers},p.data=h(n,p,e),{url:u(d),options:p}}}}(n);return{async createTransactionIntent(a,i,o){const r=await s.createTransactionIntent(a,i,o);return d(r,e,t,n)},async estimateTransactionIntentCost(a,i){const o=await s.estimateTransactionIntentCost(a,i);return d(o,e,t,n)},async getTransactionIntent(a,i,o){const r=await s.getTransactionIntent(a,i,o);return d(r,e,t,n)},async getTransactionIntents(a,i,o,r,c,h,u,l,p,y){const w=await s.getTransactionIntents(a,i,o,r,c,h,u,l,p,y);return d(w,e,t,n)},async signature(a,i,o){const r=await s.signature(a,i,o);return d(r,e,t,n)}}};class R extends n{createTransactionIntent(e,t){return O(this.configuration).createTransactionIntent(e.createTransactionIntentRequest,e.xBehalfOfProject,t).then((e=>e(this.axios,this.basePath)))}estimateTransactionIntentCost(e,t){return O(this.configuration).estimateTransactionIntentCost(e.createTransactionIntentRequest,t).then((e=>e(this.axios,this.basePath)))}getTransactionIntent(e,t){return O(this.configuration).getTransactionIntent(e.id,e.expand,t).then((e=>e(this.axios,this.basePath)))}getTransactionIntents(e={},t){return O(this.configuration).getTransactionIntents(e.limit,e.skip,e.order,e.expand,e.chainId,e.account,e.player,e.status,e.policy,t).then((e=>e(this.axios,this.basePath)))}signature(e,t){return O(this.configuration).signature(e.id,e.signatureRequest,t).then((e=>e(this.axios,this.basePath)))}}class P{apiKey;username;password;accessToken;basePath;baseOptions;formDataCtor;constructor(e={}){this.apiKey=e.apiKey,this.username=e.username,this.password=e.password,this.accessToken=e.accessToken,this.basePath=e.basePath,this.baseOptions=e.baseOptions,this.formDataCtor=e.formDataCtor}isJsonMime(e){const t=new RegExp("^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$","i");return null!==e&&(t.test(e)||"application/json-patch+json"===e.toLowerCase())}}exports.BackendApiClients=class{config;transactionIntentsApi;accountsApi;sessionsApi;authenticationApi;constructor(t){const n=e.default?e.default:e;this.config=t,this.transactionIntentsApi=new R(t.backend,void 0,n),this.accountsApi=new p(t.backend,void 0,n),this.sessionsApi=new m(t.backend,void 0,n),this.authenticationApi=new w(t.backend,void 0,n)}},exports.createConfig=({basePath:e,accessToken:t})=>{if(!e.trim())throw Error("basePath can not be empty");return new P({basePath:e,accessToken:t})};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("../../packages/internal/openapi-clients/dist/index.js"),t=require("crypto"),r=require("jose"),a=require("jsrsasign"),i=require("./errors/openfortError.js"),n=require("./types.js"),s=require("./utils/deviceCredentialsManager.js"),o=require("./utils/helpers.js");function l(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var c=l(t);function h(e){return e.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function d(e){return c.createHash("sha256").update(e).digest()}class p{publishableKey;deviceCredentialsManager;backendApiClients;constructor(t,r){this.publishableKey=t,this.deviceCredentialsManager=new s,this.backendApiClients=new e.BackendApiClients({backend:e.createConfig({basePath:r,accessToken:t})})}async initOAuth(e,t,r){const a=t?.usePooling??!1;delete t?.usePooling;const i={oAuthInitRequest:{provider:e,options:t,usePooling:a}},n=await this.backendApiClients.authenticationApi.initOAuth(i,p.getEcosystemGameOptsOrUndefined(r));return o.isBrowser()&&t?.skipBrowserRedirect&&window.location.assign(n.data.url),{url:n.data.url,key:n.data.key}}async registerGuest(){return(await this.backendApiClients.authenticationApi.registerGuest({})).data}async poolOAuth(e){const t={key:e};for(let e=0;e<600;e++)try{const e=await this.backendApiClients.authenticationApi.poolOAuth(t);if(200===e.status)return e.data}catch(e){if(e.response&&404===e.response.status){await new Promise((e=>{setTimeout(e,500)}));continue}throw e}throw new Error("Failed to pool OAuth, try again later")}async authenticateThirdParty(e,t,r,a){const n={thirdPartyOAuthRequest:{provider:e,token:t,tokenType:r}};return i.withOpenfortError((async()=>(await this.backendApiClients.authenticationApi.thirdParty(n,p.getEcosystemGameOptsOrUndefined(a))).data),{default:i.OpenfortErrorType.AUTHENTICATION_ERROR,403:i.OpenfortErrorType.USER_NOT_AUTHORIZED_ON_ECOSYSTEM})}async initSIWE(e,t){const r={sIWERequest:{address:e}},a=await this.backendApiClients.authenticationApi.initSIWE(r,p.getEcosystemGameOptsOrUndefined(t));return{address:a.data.address,nonce:a.data.nonce,expiresAt:a.data.expiresAt}}async authenticateSIWE(e,t,r,a){const n={sIWEAuthenticateRequest:{signature:e,message:t,walletClientType:r,connectorType:a}};return i.withOpenfortError((async()=>(await this.backendApiClients.authenticationApi.authenticateSIWE(n)).data),{default:i.OpenfortErrorType.AUTHENTICATION_ERROR,403:i.OpenfortErrorType.USER_NOT_AUTHORIZED_ON_ECOSYSTEM})}static getEcosystemGameOptsOrUndefined(e){if(e)return{headers:{"x-game":e}}}async loginEmailPassword(e,t,r){const a={loginRequest:{email:e,password:t}};return i.withOpenfortError((async()=>(await this.backendApiClients.authenticationApi.loginEmailPassword(a,p.getEcosystemGameOptsOrUndefined(r))).data),{default:i.OpenfortErrorType.AUTHENTICATION_ERROR,403:i.OpenfortErrorType.USER_NOT_AUTHORIZED_ON_ECOSYSTEM})}async requestResetPassword(e,t){const r=h(c.randomBytes(32)),a=h(d(r)),i=h(c.randomBytes(32));this.deviceCredentialsManager.savePKCEData({state:i,verifier:r});const s={requestResetPasswordRequest:{email:e,redirectUrl:t,challenge:{codeChallenge:a,method:n.CodeChallengeMethodEnum.S256}}};await this.backendApiClients.authenticationApi.requestResetPassword(s)}async resetPassword(e,t,r){return i.withOpenfortError((async()=>{const a=this.deviceCredentialsManager.getPKCEData();if(!a)throw new Error("No code verifier or state for PKCE");const i={resetPasswordRequest:{email:e,password:t,state:r,challenge:{codeVerifier:a.verifier}}};await this.backendApiClients.authenticationApi.resetPassword(i)}),{default:i.OpenfortErrorType.AUTHENTICATION_ERROR})}async requestEmailVerification(e,t){const r=h(c.randomBytes(32)),a=h(d(r)),i=h(c.randomBytes(32));this.deviceCredentialsManager.savePKCEData({state:i,verifier:r});const s={requestVerifyEmailRequest:{email:e,redirectUrl:t,challenge:{codeChallenge:a,method:n.CodeChallengeMethodEnum.S256}}};await this.backendApiClients.authenticationApi.requestEmailVerification(s)}async verifyEmail(e,t){return i.withOpenfortError((async()=>{const r=this.deviceCredentialsManager.getPKCEData();if(!r)throw new Error("No code verifier or state for PKCE");const a={verifyEmailRequest:{email:e,token:t,challenge:{codeVerifier:r.verifier}}};await this.backendApiClients.authenticationApi.verifyEmail(a)}),{default:i.OpenfortErrorType.AUTHENTICATION_ERROR})}async signupEmailPassword(e,t,r,a){const n={signupRequest:{email:e,password:t,name:r}};return i.withOpenfortError((async()=>(await this.backendApiClients.authenticationApi.signupEmailPassword(n,p.getEcosystemGameOptsOrUndefined(a))).data),{default:i.OpenfortErrorType.USER_REGISTRATION_ERROR,403:i.OpenfortErrorType.USER_NOT_AUTHORIZED_ON_ECOSYSTEM})}async validateCredentialsWithoutCrypto(e,t){if(!t.refreshToken)throw new i.OpenfortError("No refresh token provided",i.OpenfortErrorType.AUTHENTICATION_ERROR);const r=a.KEYUTIL.getKey({kty:e.kty,crv:e.crv,x:e.x,y:e.y}),n=a.KJUR.jws.JWS.parse(t.token);if(!a.KJUR.jws.JWS.verifyJWT(t.token,r,{alg:[e.alg]}))throw new i.OpenfortError("Invalid token signature",i.OpenfortErrorType.AUTHENTICATION_ERROR);const s=JSON.parse(n.payloadPP);if(!s.exp)return this.refreshTokens(t.refreshToken);const o=a.KJUR.jws.IntDate.getNow();return s.exp<o?this.refreshTokens(t.refreshToken):{player:s.sub,accessToken:t.token,refreshToken:t.refreshToken}}async validateCredentialsWithCrypto(e,t){if(!t.refreshToken)throw new i.OpenfortError("No refresh token provided",i.OpenfortErrorType.AUTHENTICATION_ERROR);try{const a=await r.importJWK({kty:e.kty,crv:e.crv,x:e.x,y:e.y},e.alg);return{player:(await r.jwtVerify(t.token,a)).payload.sub,accessToken:t.token,refreshToken:t.refreshToken}}catch(e){if(e instanceof r.errors.JWTExpired)return this.refreshTokens(t.refreshToken);throw e}}async validateCredentials(e,t){const r=await this.getJWK();if(!e.refreshToken)throw new i.OpenfortError("No refresh token provided",i.OpenfortErrorType.AUTHENTICATION_ERROR);if(t)return this.refreshTokens(e.refreshToken,t);const a=p.getWebCrypto();return a?.subtle?this.validateCredentialsWithCrypto(r,e):this.validateCredentialsWithoutCrypto(r,e)}jwksStorageKey="openfort.jwk";stringToJWK(e){const t=JSON.parse(e);return{kty:t.kty,crv:t.crv,x:t.x,y:t.y,alg:t.alg}}async getJWK(){const e=sessionStorage.getItem(this.jwksStorageKey);if(e)return this.stringToJWK(e);const t={publishableKey:this.publishableKey},r=await this.backendApiClients.authenticationApi.getJwks(t);if(0===r.data.keys.length)throw new i.OpenfortError("No JWKS keys found",i.OpenfortErrorType.INTERNAL_ERROR);const a=r.data.keys[0];return sessionStorage.setItem(this.jwksStorageKey,JSON.stringify(a)),{kty:a.kty,crv:a.crv,x:a.x,y:a.y,alg:a.alg}}async refreshTokens(e,t){const r={refreshTokenRequest:{refreshToken:e,forceRefresh:t}};return i.withOpenfortError((async()=>{const e=await this.backendApiClients.authenticationApi.refresh(r);return{player:e.data.player.id,accessToken:e.data.token,refreshToken:e.data.refreshToken}}),{default:i.OpenfortErrorType.REFRESH_TOKEN_ERROR})}async logout(e,t){const r={logoutRequest:{refreshToken:t}};i.withOpenfortError((async()=>{await this.backendApiClients.authenticationApi.logout(r,{headers:{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e}})}),{default:i.OpenfortErrorType.LOGOUT_ERROR})}async getUser(e){return(await this.backendApiClients.authenticationApi.me({headers:{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}})).data}async linkThirdParty(e,t,r,a,i){const n={thirdPartyLinkRequest:{provider:t,token:r,tokenType:a}};return(await this.backendApiClients.authenticationApi.linkThirdParty(n,{headers:{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider||void 0,"x-token-type":e.thirdPartyTokenType||void 0,"x-game":i||void 0}})).data}async linkOAuth(e,t,r,a){const i={oAuthInitRequest:{provider:t,options:r,usePooling:r?.usePooling||!1}},n=await this.backendApiClients.authenticationApi.linkOAuth(i,{headers:{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider||void 0,"x-token-type":e.thirdPartyTokenType||void 0,"x-game":a||void 0}});return o.isBrowser()&&!r?.skipBrowserRedirect&&window.location.assign(n.data.url),{url:n.data.url,key:n.data.key}}async unlinkOAuth(e,t){const r={unlinkOAuthRequest:{provider:e}};return(await this.backendApiClients.authenticationApi.unlinkOAuth(r,{headers:{authorization:`Bearer ${this.publishableKey}`,"x-player-token":t}})).data}async unlinkWallet(e,t){const r={sIWERequest:{address:e}};return(await this.backendApiClients.authenticationApi.unlinkSIWE(r,{headers:{authorization:`Bearer ${this.publishableKey}`,"x-player-token":t}})).data}async linkWallet(e,t,r,a,i){const n={sIWEAuthenticateRequest:{signature:e,message:t,walletClientType:r,connectorType:a}};return(await this.backendApiClients.authenticationApi.linkSIWE(n,{headers:{authorization:`Bearer ${this.publishableKey}`,"x-player-token":i}})).data}async unlinkEmail(e,t){const r={unlinkEmailRequest:{email:e}};return(await this.backendApiClients.authenticationApi.unlinkEmail(r,{headers:{authorization:`Bearer ${this.publishableKey}`,"x-player-token":t}})).data}static getWebCrypto(){return o.isBrowser()?window.crypto:"undefined"!=typeof global&&global.crypto?global.crypto:null}async linkEmail(e,t,r,a){const i={loginRequest:{email:e,password:t}};return(await this.backendApiClients.authenticationApi.linkEmail(i,{headers:{authorization:`Bearer ${this.publishableKey}`,"x-player-token":r,"x-game":a||void 0}})).data}}exports.AuthManager=p;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.chainRpcs={1:"https://cloudflare-eth.com",10:"https://optimism-rpc.publicnode.com",56:"https://bsc.publicnode.com",97:"https://bsc-testnet.publicnode.com",137:"https://polygon-rpc.com",204:"https://opbnb-mainnet-rpc.bnbchain.org",255:"https://api.kroma.network",300:"https://sepolia.era.zksync.dev",324:"https://mainnet.era.zksync.io",1946:"https://rpc.minato.soneium.org",2358:"https://api.sepolia.kroma.network",2741:"https://api.mainnet.abs.xyz",3939:"https://test.doschain.com",4337:"https://build.onbeam.com/rpc",5611:"https://opbnb-testnet-rpc.bnbchain.org",7979:"https://main.doschain.com",8453:"https://mainnet.base.org",11124:"https://api.testnet.abs.xyz",13337:"https://build.onbeam.com/rpc/testnet",13473:"https://rpc.testnet.immutable.com",42161:"https://arb1.arbitrum.io/rpc",42170:"https://nova.arbitrum.io/rpc",43113:"https://api.avax-test.network/ext/bc/C/rpc",43114:"https://api.avax.network/ext/bc/C/rpc",50104:"https://rpc.sophon.xyz",80002:"https://rpc-amoy.polygon.technology",84532:"https://sepolia.base.org",247253:"https://rpc-testnet.saakuru.network",421614:"https://sepolia-rollup.arbitrum.io/rpc",7225878:"https://rpc.saakuru.network",7777777:"https://rpc.zora.energy/",11155111:"https://ethereum-sepolia-rpc.publicnode.com",11155420:"https://optimism-sepolia-rpc.publicnode.com",28122024:"https://rpcv2-testnet.ancient8.gg",531050104:"https://rpc.testnet.sophon.xyz",666666666:"https://rpc.degen.tips",888888888:"https://rpc.ancient8.gg",999999999:"https://sepolia.rpc.zora.energy"};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("../../../packages/internal/openapi-clients/dist/index.js");exports.OpenfortConfiguration=class{publishableKey;constructor(e){this.publishableKey=e.publishableKey}},exports.SDKConfiguration=class{baseConfiguration;shieldConfiguration;shieldUrl;iframeUrl;backendUrl;openfortAPIConfig;constructor({baseConfiguration:i,shieldConfiguration:s,overrides:t}){this.shieldConfiguration=s,this.baseConfiguration=i,t?(this.backendUrl=t.backendUrl||"https://api.openfort.xyz",this.iframeUrl=t.iframeUrl||"https://embedded.openfort.xyz",this.shieldUrl=t.shieldUrl||"https://shield.openfort.xyz",this.openfortAPIConfig={backend:e.createConfig({basePath:t.backendUrl||"https://api.openfort.xyz",accessToken:i.publishableKey})}):(this.backendUrl="https://api.openfort.xyz",this.iframeUrl="https://embedded.openfort.xyz",this.shieldUrl="https://shield.openfort.xyz",this.openfortAPIConfig={backend:e.createConfig({basePath:"https://api.openfort.xyz",accessToken:i.publishableKey})})}},exports.ShieldConfiguration=class{shieldPublishableKey;shieldEncryptionKey;debug=!1;constructor(e){this.shieldPublishableKey=e.shieldPublishableKey,this.shieldEncryptionKey=e.shieldEncryptionKey,this.debug=e.shieldDebug||!1}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var s=require("../storage/istorage.js");class e{type;address;ownerAddress;chainId;constructor(s,e,r,t){this.type=s,this.address=e,this.chainId=r,this.ownerAddress=t}static fromStorage(r){const t=r.get(s.StorageKeys.ACCOUNT);if(!t)return null;const a=JSON.parse(t);return new e(a.type,a.address,a.chainId,a.ownerAddress)}save(e){e.save(s.StorageKeys.ACCOUNT,JSON.stringify(this))}}exports.Account=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("../storage/istorage.js");class r{type;token;player;refreshToken;thirdPartyProvider;thirdPartyTokenType;constructor(e,r,t,s=null,i=null,n=null){this.type=e,this.token=r,this.player=t,this.refreshToken=s,this.thirdPartyProvider=i,this.thirdPartyTokenType=n}static fromStorage(t){const s=t.get(e.StorageKeys.AUTHENTICATION);if(!s)return null;const i=JSON.parse(s);return new r(i.type,i.token,i.player,i.refreshToken??null,i.thirdPartyProvider??null,i.thirdPartyTokenType??null)}save(r){r.save(e.StorageKeys.AUTHENTICATION,JSON.stringify(this))}}exports.Authentication=r;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";let e=null;exports.Configuration=class{publishableKey;openfortURL;shieldPublishableKey;shieldEncryptionKey;shieldURL;iframeURL;debug;constructor(e,i,s,t,h,l,r=!1){this.publishableKey=e,this.openfortURL=i,this.shieldPublishableKey=s,this.shieldEncryptionKey=t,this.shieldURL=h,this.iframeURL=l,this.debug=r}static fromStorage(){return e}save(){e=this}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("../storage/istorage.js");class e{type;customToken;constructor(t,e){this.type=t,this.customToken=e}static fromStorage(s){const r=s.get(t.StorageKeys.RECOVERY);if(!r)return null;const o=JSON.parse(r);return new e(o.type,o.customToken??void 0)}save(e){e.save(t.StorageKeys.RECOVERY,JSON.stringify(this))}}exports.Recovery=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("../storage/istorage.js"),r=require("../crypto/key-pair.js");class t{key;constructor(e){this.key=e}static fromStorage(s){const a=s.get(e.StorageKeys.RECOVERY);if(!a)return null;const o=r.KeyPair.load(a);return o?new t(o):null}save(r){r.save(e.StorageKeys.RECOVERY,this.key?.getPrivateKey()??"")}}exports.Session=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("@noble/curves/secp256k1"),r=require("@ethersproject/signing-key"),t=require("@ethersproject/bytes"),s=require("@ethersproject/transactions"),i=require("@ethersproject/hash");class a extends r.SigningKey{constructor(r=e.secp256k1.utils.randomPrivateKey()){super(r)}sign(e){return t.joinSignature(this.signDigest(i.hashMessage(t.arrayify(e))))}static load(e){return e?new a(t.arrayify(e)):null}getPublicKey(){return s.computeAddress(this.privateKey)}getPrivateKey(){return this.privateKey}}exports.KeyPair=a;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var R,E=require("axios");exports.OpenfortErrorType=void 0,(R=exports.OpenfortErrorType||(exports.OpenfortErrorType={})).AUTHENTICATION_ERROR="AUTHENTICATION_ERROR",R.INVALID_CONFIGURATION="INVALID_CONFIGURATION",R.NOT_LOGGED_IN_ERROR="NOT_LOGGED_IN_ERROR",R.REFRESH_TOKEN_ERROR="REFRESH_TOKEN_ERROR",R.USER_REGISTRATION_ERROR="USER_REGISTRATION_ERROR",R.LOGOUT_ERROR="LOGOUT_ERROR",R.OPERATION_NOT_SUPPORTED_ERROR="OPERATION_NOT_SUPPORTED_ERROR",R.MISSING_SESSION_SIGNER_ERROR="MISSING_SESSION_SIGNER_ERROR",R.MISSING_EMBEDDED_SIGNER_ERROR="MISSING_EMBEDDED_SIGNER_ERROR",R.MISSING_SIGNER_ERROR="MISSING_SIGNER_ERROR",R.USER_NOT_AUTHORIZED_ON_ECOSYSTEM="USER_NOT_AUTHORIZED_ON_ECOSYSTEM",R.INTERNAL_ERROR="INTERNAL_ERROR";class O extends Error{type;data;constructor(R,E,O={}){super(R),this.type=E,this.data=O}}exports.OpenfortError=O,exports.withOpenfortError=async(R,r)=>{try{return await R()}catch(R){let e;const _={};let I=r.default;if(E.isAxiosError(R)){const E=R.response?.status;I=E&&r[E]||r.default,e=R.response?.data&&R.response.data.error&&function(R){return"type"in R&&"message"in R}(R.response.data.error)?R.response.data.error.message:R.message}else e=R.message;throw new O(e,I,_)}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var E,R;exports.ProviderErrorCode=void 0,(E=exports.ProviderErrorCode||(exports.ProviderErrorCode={}))[E.USER_REJECTED_REQUEST=4001]="USER_REJECTED_REQUEST",E[E.UNAUTHORIZED=4100]="UNAUTHORIZED",E[E.UNSUPPORTED_METHOD=4200]="UNSUPPORTED_METHOD",E[E.DISCONNECTED=4900]="DISCONNECTED",exports.RpcErrorCode=void 0,(R=exports.RpcErrorCode||(exports.RpcErrorCode={}))[R.RPC_SERVER_ERROR=-32e3]="RPC_SERVER_ERROR",R[R.INVALID_REQUEST=-32600]="INVALID_REQUEST",R[R.METHOD_NOT_FOUND=-32601]="METHOD_NOT_FOUND",R[R.INVALID_PARAMS=-32602]="INVALID_PARAMS",R[R.INTERNAL_ERROR=-32603]="INTERNAL_ERROR",R[R.PARSE_ERROR=-32700]="PARSE_ERROR",R[R.TRANSACTION_REJECTED=-32003]="TRANSACTION_REJECTED";class r extends Error{message;code;constructor(E,R){super(R),this.message=R,this.code=E}}exports.JsonRpcError=r;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=require("../manager/signer.js"),e=require("./JsonRpcError.js");const n=["chainId","chainName","nativeCurrency"],o=r=>{if(!r||"object"!=typeof r)throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,"Invalid chain parameter: expected an object");if(!(r=>n.every((e=>e in r)))(r))throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,`Invalid chain parameter. The following properties are required: ${n.join(", ")}`);if(!r.chainName||""===r.chainName.trim())throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,"chainName cannot be empty");if(!((o=r.nativeCurrency)&&"object"==typeof o&&"name"in o&&"symbol"in o&&"decimals"in o&&"string"==typeof o.name&&"string"==typeof o.symbol&&"number"==typeof o.decimals&&Number.isInteger(o.decimals)))throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,"Invalid nativeCurrency object");var o;if(0===r.rpcUrls?.length)throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,"At least one RPC URL must be provided");if(!/^0x[0-9a-fA-F]+$/.test(r.chainId))throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,"chainId must be a valid hex string");return{chainId:r.chainId,blockExplorerUrls:r.blockExplorerUrls||[],chainName:r.chainName,iconUrls:r.iconUrls||[],rpcUrls:r.rpcUrls||[],nativeCurrency:r.nativeCurrency}};exports.addEthereumChain=async({params:n,rpcProvider:a})=>{if(!n||!Array.isArray(n)||0===n.length)throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,"Invalid parameters for wallet_addEthereumChain");const i=o(n[0]),c=parseInt(i.chainId,16),{chainId:t}=await a.detectNetwork();if(c===t)return!1;try{if(!await r.SignerManager.embedded())throw new e.JsonRpcError(e.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - no account available");return null}catch(r){if(r instanceof Error)throw new e.JsonRpcError(e.RpcErrorCode.INTERNAL_ERROR,`Failed to add chain: ${r.message}`);throw new e.JsonRpcError(e.RpcErrorCode.INTERNAL_ERROR,"Failed to add chain")}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=require("../errors/openfortError.js"),t=require("./JsonRpcError.js");exports.estimateGas=async({params:e,account:a,authentication:n,backendClient:o,policyId:i})=>{const s=await(async(e,a,n,o,i)=>{const s=e.map((r=>{if(!r.to)throw new t.JsonRpcError(t.RpcErrorCode.INVALID_PARAMS,'eth_estimateGas requires a "to" field');return{to:String(r.to),data:r.data?String(r.data):void 0,value:r.value?String(r.value):void 0}}));return r.withOpenfortError((async()=>(await a.transactionIntentsApi.estimateTransactionIntentCost({createTransactionIntentRequest:{policy:i,chainId:n.chainId,interactions:s}},{headers:{authorization:`Bearer ${a.config.backend.accessToken}`,"x-player-token":o.token,"x-auth-provider":o.thirdPartyProvider,"x-token-type":o.thirdPartyTokenType}})).data),{default:r.OpenfortErrorType.AUTHENTICATION_ERROR})})(e,o,a,n,i).catch((r=>{throw new t.JsonRpcError(t.RpcErrorCode.TRANSACTION_REJECTED,r.message)}));return s.estimatedTXGas};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("@ethersproject/providers"),r=require("@ethersproject/bytes"),t=require("../configuration/authentication.js"),a=require("./types.js"),s=require("./JsonRpcError.js"),o=require("./signTypedDataV4.js"),i=require("../types.js"),n=require("../utils/typedEventEmitter.js"),c=require("../chains/index.js"),h=require("../configuration/account.js"),d=require("../manager/signer.js"),u=require("../storage/istorage.js"),g=require("./addEthereumChain.js"),l=require("./registerSession.js"),p=require("./revokeSession.js"),m=require("./sendCalls.js"),E=require("./getCallsStatus.js"),f=require("./personalSign.js"),A=require("./estimateGas.js");exports.EvmProvider=class{#e;#r;updatePolicy(e){this.#r=e}#t;#a;#s;#o;isOpenfort=!0;constructor({storage:r,backendApiClients:t,openfortEventEmitter:a,policyId:s,validateAndRefreshSession:o}){this.#e=r,this.#r=s,this.#t=o,this.#o=t;const d=h.Account.fromStorage(this.#e),u=d?.chainId||8453;this.#s=new e.StaticJsonRpcProvider(c.chainRpcs[u]),this.#o=t,this.#a=new n,a.on(i.OpenfortEvents.LOGGED_OUT,this.#i)}#i=()=>{const e=!!h.Account.fromStorage(this.#e),r=d.SignerManager.fromStorage();r?.logout(),this.#e.remove(u.StorageKeys.ACCOUNT),this.#e.remove(u.StorageKeys.AUTHENTICATION),this.#e.remove(u.StorageKeys.SIGNER),e&&this.#a.emit(a.ProviderEvent.ACCOUNTS_CHANGED,[])};async#n(i){switch(i.method){case"eth_accounts":{const e=h.Account.fromStorage(this.#e);return e?[e.address]:[]}case"eth_requestAccounts":{let e=h.Account.fromStorage(this.#e);if(e)return this.#a.emit(a.ProviderEvent.ACCOUNTS_CONNECT,{chainId:r.hexlify(e.chainId)}),[e.address];if(!d.SignerManager.fromStorage())throw new s.JsonRpcError(s.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - must be authenticated and configured with a signer");if(await d.SignerManager.embedded(),e=h.Account.fromStorage(this.#e),!e)throw new s.JsonRpcError(s.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - no account available");return this.#a.emit(a.ProviderEvent.ACCOUNTS_CHANGED,[e.address]),[e.address]}case"eth_sendTransaction":{const e=h.Account.fromStorage(this.#e),r=d.SignerManager.fromStorage(),a=t.Authentication.fromStorage(this.#e);if(!e||!r||!a)throw new s.JsonRpcError(s.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return this.#t(),await m.sendCalls({params:i.params||[],signer:r,account:e,authentication:a,backendClient:this.#o,policyId:this.#r})}case"eth_estimateGas":{const e=h.Account.fromStorage(this.#e),r=t.Authentication.fromStorage(this.#e);if(!e||!r)throw new s.JsonRpcError(s.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return this.#t(),await A.estimateGas({params:i.params||[],account:e,authentication:r,backendClient:this.#o,policyId:this.#r})}case"eth_signTypedData":case"eth_signTypedData_v4":{const e=h.Account.fromStorage(this.#e),r=d.SignerManager.fromStorage();if(!e||!r)throw new s.JsonRpcError(s.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return this.#t(),await o.signTypedDataV4({method:i.method,params:i.params||[],signer:r,accountType:e.type,rpcProvider:this.#s})}case"personal_sign":{const e=h.Account.fromStorage(this.#e),r=d.SignerManager.fromStorage();if(!e||!r)throw new s.JsonRpcError(s.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return this.#t(),await f.personalSign({params:i.params||[],signer:r,account:e})}case"eth_chainId":{const{chainId:e}=await this.#s.detectNetwork();return r.hexlify(e)}case"wallet_switchEthereumChain":{const r=d.SignerManager.fromStorage();if(!r)throw new s.JsonRpcError(s.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - must be authenticated and configured with a signer");if(!i.params||!Array.isArray(i.params)||0===i.params.length)throw new s.JsonRpcError(s.RpcErrorCode.INVALID_PARAMS,"Invalid parameters for wallet_switchEthereumChain");this.#t();try{const t=parseInt(i.params[0].chainId,16);await r.switchChain({chainId:t}),this.#s=new e.StaticJsonRpcProvider(c.chainRpcs[t])}catch(e){throw new s.JsonRpcError(s.RpcErrorCode.INTERNAL_ERROR,"Failed to switch chain")}return null}case"wallet_addEthereumChain":if(!d.SignerManager.fromStorage())throw new s.JsonRpcError(s.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - must be authenticated and configured with a signer");return await g.addEthereumChain({params:i.params||[],rpcProvider:this.#s});case"wallet_showCallsStatus":return null;case"wallet_getCallsStatus":{const e=h.Account.fromStorage(this.#e),r=d.SignerManager.fromStorage(),a=t.Authentication.fromStorage(this.#e);if(!e||!r||!a)throw new s.JsonRpcError(s.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return this.#t(),await E.getCallStatus({params:i.params||{},authentication:a,backendClient:this.#o,account:e})}case"wallet_sendCalls":{const e=h.Account.fromStorage(this.#e),r=d.SignerManager.fromStorage(),a=t.Authentication.fromStorage(this.#e);if(!e||!r||!a)throw new s.JsonRpcError(s.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return this.#t(),await m.sendCalls({params:i.params?i.params[0].calls:[],signer:r,account:e,authentication:a,backendClient:this.#o,policyId:this.#r})}case"wallet_grantPermissions":{const e=h.Account.fromStorage(this.#e),r=d.SignerManager.fromStorage(),a=t.Authentication.fromStorage(this.#e);if(!e||!r||!a)throw new s.JsonRpcError(s.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return this.#t(),await l.registerSession({params:i.params||[],signer:r,account:e,authentication:a,backendClient:this.#o,policyId:this.#r})}case"wallet_revokePermissions":{const e=h.Account.fromStorage(this.#e),r=d.SignerManager.fromStorage(),a=t.Authentication.fromStorage(this.#e);if(!e||!r||!a)throw new s.JsonRpcError(s.ProviderErrorCode.UNAUTHORIZED,"Unauthorized - call eth_requestAccounts first");return this.#t(),await p.revokeSession({params:i.params||[],signer:r,account:e,authentication:a,backendClient:this.#o})}case"wallet_getCapabilities":{const{chainId:e}=await this.#s.detectNetwork();return{[r.hexlify(e)]:{permissions:{supported:!0,signerTypes:["account","key"],keyTypes:["secp256k1"],permissionTypes:["contract-calls"]},paymasterService:{supported:!0},atomicBatch:{supported:!0}}}}case"eth_gasPrice":case"eth_getBalance":case"eth_getCode":case"eth_getStorageAt":case"eth_call":case"eth_blockNumber":case"eth_getBlockByHash":case"eth_getBlockByNumber":case"eth_getTransactionByHash":case"eth_getTransactionReceipt":case"eth_getTransactionCount":return this.#s.send(i.method,i.params||[]);default:throw new s.JsonRpcError(s.ProviderErrorCode.UNSUPPORTED_METHOD,`${i.method}: Method not supported`)}}async request(e){try{return this.#n(e)}catch(e){if(e instanceof s.JsonRpcError)throw e;if(e instanceof Error)throw new s.JsonRpcError(s.RpcErrorCode.INTERNAL_ERROR,e.message);throw new s.JsonRpcError(s.RpcErrorCode.INTERNAL_ERROR,"Internal error")}}on(e,r){this.#a.on(e,r)}removeListener(e,r){this.#a.removeListener(e,r)}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("../errors/openfortError.js"),r=require("./JsonRpcError.js");exports.getCallStatus=async({params:s,authentication:t,backendClient:a})=>{const o=await(async(r,s,t)=>e.withOpenfortError((async()=>(await s.transactionIntentsApi.getTransactionIntent({id:r},{headers:{authorization:`Bearer ${s.config.backend.accessToken}`,"x-player-token":t.token,"x-auth-provider":t.thirdPartyProvider,"x-token-type":t.thirdPartyTokenType}})).data),{default:e.OpenfortErrorType.AUTHENTICATION_ERROR}))(s[0],a,t).catch((e=>{throw new r.JsonRpcError(r.RpcErrorCode.TRANSACTION_REJECTED,e.message)}));return{status:o.response?"CONFIRMED":"PENDING",receipts:o.response?[{status:0===o.response.status?"reverted":"success",logs:o.response.logs?.map((e=>({address:e.address,data:e.data,topics:e.topics})))||[],blockHash:o.response.transactionHash||"",blockNumber:BigInt(o.response.blockNumber||0),gasUsed:BigInt(o.response.gasUsed||0),transactionHash:o.response.transactionHash||""}]:void 0}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=require("./JsonRpcError.js");exports.personalSign=async({params:e,signer:s,account:o})=>{const n=e[0],a=e[1];if(!a||!n)throw new r.JsonRpcError(r.RpcErrorCode.INVALID_PARAMS,"personal_sign requires an address and a message");if(a.toLowerCase()!==o.address.toLowerCase())throw new r.JsonRpcError(r.RpcErrorCode.INVALID_PARAMS,"personal_sign requires the signer to be the from address");return await s.sign(n,!1,!0)};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e={icon:'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="597.32 331.34 171.36 105.32" ><g><rect x="673.9" y="404.26" width="18.2" height="32.4" /><polygon points="768.68,331.36 768.68,331.36 768.68,331.34 610.78,331.34 610.78,331.36 597.32,331.36 597.32,436.64 615.52,436.64 615.52,349.54 750.48,349.54 750.48,436.64 768.68,436.64 " /><polygon points="732.16,367.79 633.83,367.79 633.83,370.19 633.79,370.19 633.79,436.64 651.99,436.64 651.99,385.99 713.9,385.99 713.9,436.64 732.09,436.64 732.09,385.99 732.16,385.99 " /></g></svg>',name:"Openfort",rdns:"xyz.openfort",uuid:crypto.randomUUID()};exports.announceProvider=function(e){if("undefined"==typeof window)return;const n=new CustomEvent("eip6963:announceProvider",{detail:Object.freeze(e)});window.dispatchEvent(n),window.addEventListener("eip6963:requestProvider",(()=>window.dispatchEvent(n)))},exports.openfortProviderInfo=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("../errors/openfortError.js"),t=require("./JsonRpcError.js");function r(e){return{data:"token-allowance"===e.type?{allowance:e.data.allowance.toString()}:"gas-limit"===e.type?{limit:e.data.limit.toString()}:e.data,type:"string"==typeof e.type?e.type:e.type.custom}}function i(e){return{...e,policies:e.policies.map(r),required:e.required??!1,type:"string"==typeof e.type?e.type:e.type.custom}}function s(e){return{expiry:e.validUntil?Number(e.validUntil):0,grantedPermissions:e.whitelist?e.whitelist.map((t=>({type:"contract-call",data:{address:t,calls:[]},policies:[{data:{limit:e.limit},type:{custom:"usage-limit"}}]}))):[],permissionsContext:e.id}}exports.registerSession=async({params:r,signer:a,account:n,authentication:o,backendClient:c,policyId:p})=>{const d=await(async(r,s,a,n,o)=>{const c=r[0],p=Math.floor((new Date).getTime()/1e3),d=Math.floor(new Date(Date.now()+1e3*c.expiry).getTime()/1e3),l=c.permissions.map(i),y=l.filter((e=>"contract-call"===e.type||"erc20-token-transfer"===e.type)).map((e=>e.data.address)),u=l[0].policies.find((e=>"usage-limit"===e.type))?.data?.limit;if(c.signer&&"keys"===c.signer.type)throw new t.JsonRpcError(t.RpcErrorCode.INVALID_PARAMS,"Failed to request permissions - missing session address");const m=c.signer?.data?.id;if(!m)throw new t.JsonRpcError(t.RpcErrorCode.INVALID_PARAMS,"Failed to request permissions - missing session address");const g=((e,t,r,i,s,a=!1,n,o,c,p)=>{const d={address:e,chainId:t,validAfter:r,validUntil:i,optimistic:a,whitelist:n,player:o};return s&&(d.policy=s),p&&(d.externalOwnerAddress=p),c&&(d.limit=c),d})(m,a.chainId,p,d,o,!1,y,n.player,u);return e.withOpenfortError((async()=>(await s.sessionsApi.createSession({createSessionRequest:g},{headers:{authorization:`Bearer ${s.config.backend.accessToken}`,"x-player-token":n.token,"x-auth-provider":n.thirdPartyProvider,"x-token-type":n.thirdPartyTokenType}})).data),{default:e.OpenfortErrorType.AUTHENTICATION_ERROR})})(r,c,n,o,p).catch((e=>{throw new t.JsonRpcError(t.RpcErrorCode.TRANSACTION_REJECTED,e.message)}));if(d?.nextAction?.payload?.signableHash){let r;r=[300,531050104,324,50104,2741,11124].includes(n.chainId)?await a.sign(d.nextAction.payload.signableHash,!1,!1):await a.sign(d.nextAction.payload.signableHash);return s(await e.withOpenfortError((async()=>(await c.sessionsApi.signatureSession({id:d.id,signatureRequest:{signature:r}})).data),{default:e.OpenfortErrorType.AUTHENTICATION_ERROR}).catch((e=>{throw new t.JsonRpcError(t.RpcErrorCode.TRANSACTION_REJECTED,e.message)})))}if(!1===d.isActive)throw new t.JsonRpcError(t.RpcErrorCode.TRANSACTION_REJECTED,"Failed to grant permissions");return s(d)};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("../errors/openfortError.js"),r=require("./JsonRpcError.js");exports.revokeSession=async({params:a,signer:n,account:t,authentication:s,backendClient:o,policyId:i})=>{const c=a[0];if(!c.permissionContext)return await n.logout(),{};const p=await(async(r,a,n,t,s)=>{const o=((e,r,a,n)=>{const t={address:e,chainId:r,player:a};return n&&(t.policy=n),t})(r.permissionContext,n.chainId,t.player,s);return e.withOpenfortError((async()=>(await a.sessionsApi.revokeSession({revokeSessionRequest:o},{headers:{authorization:`Bearer ${a.config.backend.accessToken}`,"x-player-token":t.token,"x-auth-provider":t.thirdPartyProvider,"x-token-type":t.thirdPartyTokenType}})).data),{default:e.OpenfortErrorType.AUTHENTICATION_ERROR})})(c,o,t,s,i).catch((e=>{throw new r.JsonRpcError(r.RpcErrorCode.TRANSACTION_REJECTED,e.message)}));if(p?.nextAction?.payload?.signableHash){let e;e=[300,531050104,324,50104,2741,11124].includes(t.chainId)?await n.sign(p.nextAction.payload.signableHash,!1,!1):await n.sign(p.nextAction.payload.signableHash);return(await o.sessionsApi.signatureSession({id:p.id,signatureRequest:{signature:e}}).catch((e=>{throw new r.JsonRpcError(r.RpcErrorCode.TRANSACTION_REJECTED,e.message)}))).data}return p};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=require("../errors/openfortError.js"),e=require("./JsonRpcError.js");exports.sendCalls=async({params:a,signer:t,account:n,authentication:o,backendClient:s,policyId:i})=>{const c=a[0]?.capabilities?.paymasterService?.policy??i,p=await(async(a,t,n,o,s)=>{const i=a.map((r=>{if(!r.to)throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,'wallet_sendCalls requires a "to" field');return{to:String(r.to),data:r.data?String(r.data):void 0,value:r.value?String(r.value):void 0}}));return r.withOpenfortError((async()=>(await t.transactionIntentsApi.createTransactionIntent({createTransactionIntentRequest:{policy:s,chainId:n.chainId,interactions:i}},{headers:{authorization:`Bearer ${t.config.backend.accessToken}`,"x-player-token":o.token,"x-auth-provider":o.thirdPartyProvider,"x-token-type":o.thirdPartyTokenType}})).data),{default:r.OpenfortErrorType.AUTHENTICATION_ERROR})})(a,s,n,o,c).catch((r=>{throw new e.JsonRpcError(e.RpcErrorCode.TRANSACTION_REJECTED,r.message)}));if(p.response?.error.reason)throw new e.JsonRpcError(e.RpcErrorCode.TRANSACTION_REJECTED,p.response?.error.reason);if(p?.nextAction?.payload?.signableHash){let a;a=[300,531050104,324,50104,2741,11124].includes(n.chainId)?await t.sign(p.nextAction.payload.signableHash,!1,!1):await t.sign(p.nextAction.payload.signableHash);const o=await r.withOpenfortError((async()=>await s.transactionIntentsApi.signature({id:p.id,signatureRequest:{signature:a}})),{default:r.OpenfortErrorType.AUTHENTICATION_ERROR}).catch((r=>{throw new e.JsonRpcError(e.RpcErrorCode.TRANSACTION_REJECTED,r.message)}));if(0===o.data.response?.status)throw new e.JsonRpcError(e.RpcErrorCode.TRANSACTION_REJECTED,o.data.response?.error.reason);return o.data.response?.transactionHash}return p.response?.transactionHash};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=require("./walletHelpers.js"),e=require("./JsonRpcError.js");const t=["types","domain","primaryType","message"],a=(r,a)=>{let o;if("string"==typeof r)try{o=JSON.parse(r)}catch(r){throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,`Failed to parse typed data JSON: ${r}`)}else{if("object"!=typeof r)throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,`Invalid typed data argument: ${r}`);o=r}if(!(r=>t.every((e=>e in r)))(o))throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,`Invalid typed data argument. The following properties are required: \n ${t.join(", ")}`);const n=o.domain?.chainId;if(n&&("string"==typeof n&&(n.startsWith("0x")?o.domain.chainId=parseInt(n,16):o.domain.chainId=parseInt(n,10)),o.domain.chainId!==a))throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,`Invalid chainId, expected ${a}`);return o};exports.signTypedDataV4=async({params:t,method:o,signer:n,accountType:d,rpcProvider:i})=>{const s=t[0],p=t[1];if(!s||!p)throw new e.JsonRpcError(e.RpcErrorCode.INVALID_PARAMS,`${o} requires an address and a typed data JSON`);const{chainId:c}=await i.detectNetwork(),I=a(p,c);return await r.getSignedTypedData(I,d,c,n,s)};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var E,t;exports.BackendTransactionStatus=void 0,(E=exports.BackendTransactionStatus||(exports.BackendTransactionStatus={})).PENDING="PENDING",E.SUBMITTED="SUBMITTED",E.SUCCESSFUL="SUCCESSFUL",E.REVERTED="REVERTED",E.FAILED="FAILED",E.CANCELLED="CANCELLED",exports.ProviderEvent=void 0,(t=exports.ProviderEvent||(exports.ProviderEvent={})).ACCOUNTS_CHANGED="accountsChanged",t.ACCOUNTS_CONNECT="connect";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("@ethersproject/hash"),s=require("../types.js");exports.getSignedTypedData=async(t,a,n,r,c)=>{const o={...t.types};delete o.EIP712Domain;let i=e._TypedDataEncoder.hash(t.domain,o,t.message);if([s.AccountType.UPGRADEABLE_V5,s.AccountType.UPGRADEABLE_V6,s.AccountType.ZKSYNC_UPGRADEABLE_V1,s.AccountType.ZKSYNC_UPGRADEABLE_V2].includes(a)){const s={name:"Openfort",version:"0.5",chainId:Number(n),verifyingContract:c},t={OpenfortMessage:[{name:"hashedMessage",type:"bytes32"}]},a={hashedMessage:i};i=e._TypedDataEncoder.hash(s,t,a)}return await r.sign(i,!1,!1)};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("../storage/istorage.js"),t=require("../storage/localStorage.js"),r=require("./types.js");class s extends Error{constructor(){super("This embedded signer requires a password to be recovered")}}class o extends Error{constructor(){super("MissingProjectEntropyError")}}class i extends Error{constructor(){super("Wrong recovery password for this embedded signer")}}class n extends Error{constructor(){super("No response from iframe")}}class a extends Error{message;constructor(e){super(`Unknown response from iframe: ${e}`),this.message=e||""}}class d extends Error{constructor(){super("Invalid response from iframe")}}class h extends Error{constructor(){super("Not configured")}}exports.IframeManager=class{iframe;responses=new Map;storage;sdkConfiguration;constructor(e){this.sdkConfiguration=e,this.storage=new t.LocalStorage}async iframeSetup(){if(window.addEventListener){window.addEventListener("message",(e=>{if(e.origin===this.sdkConfiguration.iframeUrl){const{data:t}=e;t.action&&(t.action===r.Event.PONG&&this.responses.set("FIRST",t),this.responses.set(t.uuid,t))}}));const e=document.getElementById("openfort-iframe");e&&document.body.removeChild(e);const t=document.createElement("iframe");t.style.display="none",t.id="openfort-iframe",document.body.appendChild(t),this.sdkConfiguration.shieldConfiguration?.debug?t.src=`${this.sdkConfiguration.iframeUrl}?debug=true`:t.src=this.sdkConfiguration.iframeUrl,this.iframe=t}else{if(!global.openfortListener)return;global.openfortListener((e=>{if(e.origin===this.sdkConfiguration.iframeUrl){let{data:t}=e;"string"==typeof t&&(t=JSON.parse(t)),t.action&&this.responses.set(t.uuid,t)}})),this.iframe={contentWindow:{postMessage:e=>{global.openfortPostMessage&&global.openfortPostMessage(e)}}}}}isLoaded(){return void 0!==this.responses.get("FIRST")}async waitForIframeLoad(){this.iframe||await this.iframeSetup();const e=async()=>{this.isLoaded()||(this.iframe?.contentWindow?.postMessage(new r.PingRequest(this.generateShortUUID()),"*"),await new Promise((e=>{setTimeout(e,100)})),await e())};await e()}responseConstructors={[r.Event.CONFIGURED]:r.ConfigureResponse,[r.Event.AUTHENTICATION_UPDATED]:r.UpdateAuthenticationResponse,[r.Event.CURRENT_DEVICE]:r.GetCurrentDeviceResponse,[r.Event.SIGNED]:r.SignResponse,[r.Event.CHAIN_SWITCHED]:r.SwitchChainResponse,[r.Event.LOGGED_OUT]:r.LogoutResponse,[r.Event.SET_RECOVERY_METHOD]:r.SetRecoveryMethodResponse,[r.Event.EXPORT]:r.ExportPrivateKeyResponse};waitForResponse(e){return new Promise(((t,c)=>{let u=0;const f=setInterval((()=>{u>100&&(clearInterval(f),c(n)),u++;const p=this.responses.get(e);if(p){clearInterval(f),this.responses.delete(e);const n=this.responseConstructors[p.action];r.isErrorResponse(p)?(p.error===r.NOT_CONFIGURED_ERROR?c(new h):p.error===r.MISSING_USER_ENTROPY_ERROR?c(new s):p.error===r.MISSING_PROJECT_ENTROPY_ERROR?c(new o):p.error===r.INCORRECT_USER_ENTROPY_ERROR&&c(new i),c(new a(p.error))):n?t(p):c(new d)}}),100)}))}async configure(t){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");await this.waitForIframeLoad();const o={uuid:this.generateShortUUID(),action:r.Event.CONFIGURE,chainId:t.chainId,recovery:t.recovery,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,shieldAPIKey:this.sdkConfiguration.shieldConfiguration.shieldPublishableKey,accessToken:t.accessToken,playerID:t.playerID,thirdPartyProvider:t.thirdPartyProvider,thirdPartyTokenType:t.thirdPartyTokenType,encryptionKey:t.password,encryptionPart:this.sdkConfiguration?.shieldConfiguration?.shieldEncryptionKey??null,encryptionSession:t.recovery?.encryptionSession??null,openfortURL:this.sdkConfiguration.backendUrl,shieldURL:this.sdkConfiguration.shieldUrl};let n;this.iframe?.contentWindow?.postMessage(o,"*");try{n=await this.waitForResponse(o.uuid)}catch(t){throw(t instanceof i||t instanceof s)&&this.storage.remove(e.StorageKeys.SIGNER),t}return sessionStorage.setItem("iframe-version",n.version??"undefined"),n}async sign(e,t,s,o){await this.waitForIframeLoad();const i=this.generateShortUUID(),n={thirdPartyProvider:e.thirdPartyProvider??void 0,thirdPartyTokenType:e.thirdPartyTokenType??void 0,token:e.accessToken??void 0,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl},a=new r.SignRequest(i,t,s,o,n);let d;this.iframe?.contentWindow?.postMessage(a,"*");try{d=await this.waitForResponse(i)}catch(r){if(r instanceof h)return await this.configure(e),this.sign(e,t,s,o);throw r}return sessionStorage.setItem("iframe-version",d.version??"undefined"),d.signature}async switchChain(e,t){await this.waitForIframeLoad();const s=this.generateShortUUID(),o={thirdPartyProvider:e.thirdPartyProvider??void 0,thirdPartyTokenType:e.thirdPartyTokenType??void 0,token:e.accessToken??void 0,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl},i=new r.SwitchChainRequest(s,t,o);let n;this.iframe?.contentWindow?.postMessage(i,"*");try{n=await this.waitForResponse(s)}catch(r){if(r instanceof h)return await this.configure(e),this.switchChain(e,t);throw r}return sessionStorage.setItem("iframe-version",n.version??"undefined"),n}async export(e){await this.waitForIframeLoad();const t=this.generateShortUUID(),s={thirdPartyProvider:e.thirdPartyProvider??void 0,thirdPartyTokenType:e.thirdPartyTokenType??void 0,token:e.accessToken??void 0,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl},o=new r.ExportPrivateKeyRequest(t,s);let i;this.iframe?.contentWindow?.postMessage(o,"*");try{i=await this.waitForResponse(t)}catch(t){if(t instanceof h)return await this.configure(e),this.export(e);throw t}return sessionStorage.setItem("iframe-version",i.version??"undefined"),i.key}async setEmbeddedRecovery(e,t,s,o){await this.waitForIframeLoad();const i=this.generateShortUUID(),n={thirdPartyProvider:e.thirdPartyProvider??void 0,thirdPartyTokenType:e.thirdPartyTokenType??void 0,token:e.accessToken??void 0,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl},a=new r.SetRecoveryMethodRequest(i,t,s,o,n);let d;this.iframe?.contentWindow?.postMessage(a,"*");try{d=await this.waitForResponse(i)}catch(r){if(r instanceof h)return await this.configure(e),this.setEmbeddedRecovery(e,t,s,o);throw r}return sessionStorage.setItem("iframe-version",d.version??"undefined"),Promise.resolve()}async getCurrentUser(e){await this.waitForIframeLoad();const t=this.generateShortUUID(),s=new r.GetCurrentDeviceRequest(t,e);this.iframe?.contentWindow?.postMessage(s,"*");try{const e=await this.waitForResponse(t);return sessionStorage.setItem("iframe-version",e.version??"undefined"),e}catch(e){if(e instanceof h)return null;throw e}}async logout(){await this.waitForIframeLoad();const e=this.generateShortUUID(),t=new r.LogoutRequest(e);this.iframe?.contentWindow?.postMessage(t,"*"),await this.waitForResponse(e)}async updateAuthentication(e,t,s){e.accessToken=t,s===r.ShieldAuthType.OPENFORT&&e.recovery&&(e.recovery.token=t),await this.waitForIframeLoad();const o=this.generateShortUUID(),i=new r.UpdateAuthenticationRequest(o,t);this.iframe?.contentWindow?.postMessage(i,"*");try{await this.waitForResponse(o)}catch(r){if(r instanceof h)return await this.configure(e),void await this.updateAuthentication(e,t,s);throw r}}generateShortUUID(e=8){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let r="";for(let s=0;s<e;s++)r+=t.charAt(Math.floor(62*Math.random()));return r}},exports.InvalidResponseError=d,exports.MissingProjectEntropyError=o,exports.MissingRecoveryPasswordError=s,exports.NoResponseError=n,exports.NotConfiguredError=h,exports.UnknownResponseError=a,exports.WrongRecoveryPasswordError=i;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var s,e=require("../version.js");exports.Event=void 0,(s=exports.Event||(exports.Event={})).LOADED="loaded",s.CONFIGURE="configure",s.CONFIGURED="configured",s.UPDATE_AUTHENTICATION="update-authentication",s.AUTHENTICATION_UPDATED="authentication-updated",s.SIGN="sign",s.SET_RECOVERY_METHOD="set-recovery-method",s.SWITCH_CHAIN="switch-chain",s.CHAIN_SWITCHED="chain-switched",s.EXPORT="export",s.SIGNED="signed",s.LOGOUT="logout",s.LOGGED_OUT="logged-out",s.GET_CURRENT_DEVICE="get-current-device",s.CURRENT_DEVICE="current-device",s.PING="ping",s.PONG="pong";var t;exports.ShieldAuthType=void 0,(t=exports.ShieldAuthType||(exports.ShieldAuthType={})).OPENFORT="openfort",t.CUSTOM="custom",exports.ConfigureResponse=class{uuid;success;deviceID;address;chainId;accountType;ownerAddress;action=exports.Event.CONFIGURED;version;constructor(s,e,t,i,r,o){this.success=!0,this.deviceID=e,this.uuid=s,this.accountType=t,this.chainId=i,this.address=r,this.ownerAddress=o,this.version=null}},exports.ExportPrivateKeyRequest=class{uuid;action=exports.Event.EXPORT;requestConfiguration;constructor(s,e){this.uuid=s,this.requestConfiguration=e}},exports.ExportPrivateKeyResponse=class{uuid;success;action=exports.Event.EXPORT;key;version=e.VERSION;constructor(s,e){this.success=!0,this.key=e,this.uuid=s}},exports.GetCurrentDeviceRequest=class{uuid;action=exports.Event.GET_CURRENT_DEVICE;playerID;constructor(s,e){this.uuid=s,this.playerID=e}},exports.GetCurrentDeviceResponse=class{uuid;success;action=exports.Event.CURRENT_DEVICE;deviceID;accountType;version=null;chainId;address;constructor(s,e,t,i,r){this.uuid=s,this.success=!0,this.deviceID=e,this.accountType=t,this.chainId=i,this.address=r}},exports.INCORRECT_USER_ENTROPY_ERROR="incorrect-user-entropy-error",exports.LogoutRequest=class{uuid;action=exports.Event.LOGOUT;constructor(s){this.uuid=s}},exports.LogoutResponse=class{uuid;success;action=exports.Event.LOGGED_OUT;constructor(s){this.success=!0,this.uuid=s}},exports.MISSING_PROJECT_ENTROPY_ERROR="missing-project-entropy-error",exports.MISSING_USER_ENTROPY_ERROR="missing-user-entropy-error",exports.NOT_CONFIGURED_ERROR="not-configured-error",exports.PingRequest=class{uuid;action=exports.Event.PING;constructor(s){this.uuid=s}},exports.SetRecoveryMethodRequest=class{uuid;action=exports.Event.SET_RECOVERY_METHOD;recoveryMethod;recoveryPassword;encryptionSession;requestConfiguration;constructor(s,e,t,i,r){this.uuid=s,this.recoveryMethod=e,this.recoveryPassword=t,this.encryptionSession=i,this.requestConfiguration=r}},exports.SetRecoveryMethodResponse=class{uuid;success;action=exports.Event.SET_RECOVERY_METHOD;version=e.VERSION;constructor(s){this.success=!0,this.uuid=s}},exports.SignRequest=class{uuid;action=exports.Event.SIGN;message;requireArrayify;requireHash;requestConfiguration;constructor(s,e,t,i,r){this.uuid=s,this.message=e,this.requireArrayify=t,this.requireHash=i,this.requestConfiguration=r}},exports.SignResponse=class{uuid;success;signature;action=exports.Event.SIGNED;version;constructor(s,e){this.success=!0,this.signature=e,this.uuid=s,this.version=null}},exports.SwitchChainRequest=class{uuid;action=exports.Event.SWITCH_CHAIN;chainId;requestConfiguration;constructor(s,e,t){this.uuid=s,this.chainId=e,this.requestConfiguration=t}},exports.SwitchChainResponse=class{uuid;success;deviceID;address;chainId;accountType;ownerAddress;version;action=exports.Event.CHAIN_SWITCHED;constructor(s,e,t,i,r,o){this.success=!0,this.deviceID=e,this.uuid=s,this.accountType=t,this.chainId=i,this.address=r,this.ownerAddress=o,this.version=null}},exports.UpdateAuthenticationRequest=class{uuid;action=exports.Event.UPDATE_AUTHENTICATION;accessToken;recovery;constructor(s,e,t){this.uuid=s,this.accessToken=e,this.recovery=t}},exports.UpdateAuthenticationResponse=class{uuid;success;action=exports.Event.AUTHENTICATION_UPDATED;version;constructor(s){this.success=!0,this.uuid=s,this.version=null}},exports.isErrorResponse=function(s){return"error"in s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./openfort.js"),r=require("./errors/openfortError.js"),t=require("./types.js"),o=require("./iframe/types.js"),n=require("./iframe/iframeManager.js"),i=require("./config/config.js");const u=e.Openfort;exports.Openfort=e.Openfort,exports.OpenfortError=r.OpenfortError,Object.defineProperty(exports,"OpenfortErrorType",{enumerable:!0,get:function(){return r.OpenfortErrorType}}),Object.defineProperty(exports,"AuthType",{enumerable:!0,get:function(){return t.AuthType}}),Object.defineProperty(exports,"BasicAuthProvider",{enumerable:!0,get:function(){return t.BasicAuthProvider}}),Object.defineProperty(exports,"EmbeddedState",{enumerable:!0,get:function(){return t.EmbeddedState}}),Object.defineProperty(exports,"OAuthProvider",{enumerable:!0,get:function(){return t.OAuthProvider}}),Object.defineProperty(exports,"RecoveryMethod",{enumerable:!0,get:function(){return t.RecoveryMethod}}),Object.defineProperty(exports,"ThirdPartyOAuthProvider",{enumerable:!0,get:function(){return t.ThirdPartyOAuthProvider}}),Object.defineProperty(exports,"TokenType",{enumerable:!0,get:function(){return t.TokenType}}),Object.defineProperty(exports,"ShieldAuthType",{enumerable:!0,get:function(){return o.ShieldAuthType}}),exports.MissingProjectEntropyError=n.MissingProjectEntropyError,exports.MissingRecoveryPasswordError=n.MissingRecoveryPasswordError,exports.NotConfiguredError=n.NotConfiguredError,exports.WrongRecoveryPasswordError=n.WrongRecoveryPasswordError,exports.OpenfortConfiguration=i.OpenfortConfiguration,exports.SDKConfiguration=i.SDKConfiguration,exports.ShieldConfiguration=i.ShieldConfiguration,exports.default=u;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("../crypto/key-pair.js"),r=require("../../../packages/internal/openapi-clients/dist/index.js"),t=require("../storage/istorage.js"),o=require("../iframe/iframeManager.js"),n=require("../storage/localStorage.js"),i=require("../configuration/authentication.js"),s=require("../errors/openfortError.js"),a=require("../iframe/types.js"),c=require("../configuration/configuration.js"),u=require("../configuration/recovery.js"),d=require("../signer/embedded.js"),h=require("../configuration/session.js"),g=require("../signer/session.js"),y=require("../configuration/account.js");let f=null;class l{static storage=new n.LocalStorage;static fromStorage(){const e=this.storage.get(t.StorageKeys.SIGNER);if(!e)return null;const r=JSON.parse(e);if("embedded"===r.type)return this.embeddedFromStorage(r.chainId);if("session"===r.type){const e=h.Session.fromStorage(this.storage);if(!e)throw new s.OpenfortError("Must have a session to create a signer",s.OpenfortErrorType.INVALID_CONFIGURATION);return new g.SessionSigner(e.key,this.storage)}return null}static embeddedFromStorage(e){const{iframeManager:r}=this,t=i.Authentication.fromStorage(this.storage);if(!t)throw new s.OpenfortError("Must be authenticated to create a signer",s.OpenfortErrorType.NOT_LOGGED_IN_ERROR);const o=u.Recovery.fromStorage(this.storage);if(!o)throw new s.OpenfortError("Must have recovery to create a signer",s.OpenfortErrorType.INVALID_CONFIGURATION);const n={thirdPartyTokenType:t.thirdPartyTokenType,thirdPartyProvider:t.thirdPartyProvider,accessToken:t.token,playerID:t.player,recovery:this.shieldAuthentication(o,t,null),chainId:e,password:null};return new d.EmbeddedSigner(r,n,this.storage)}static get iframeManager(){if(f)return f;const e=c.Configuration.fromStorage();if(!e)throw new s.OpenfortError("Must be configured to create a signer",s.OpenfortErrorType.INVALID_CONFIGURATION);const t=new o.IframeManager({backendUrl:e.openfortURL,baseConfiguration:{publishableKey:e.publishableKey},iframeUrl:e.iframeURL,openfortAPIConfig:{backend:r.createConfig({basePath:e.openfortURL,accessToken:e.publishableKey})},shieldConfiguration:{shieldPublishableKey:e.shieldPublishableKey,shieldEncryptionKey:e.shieldEncryptionKey,debug:e.debug},shieldUrl:e.shieldURL});return f=t,t}static session(){let r=h.Session.fromStorage(this.storage);return r||(r=new h.Session(new e.KeyPair)),new g.SessionSigner(r.key,this.storage)}static async embedded(e=null,r=null,o=null,n=null){const{iframeManager:a}=this,c=i.Authentication.fromStorage(this.storage);if(!c)throw new s.OpenfortError("Must be authenticated to create a signer",s.OpenfortErrorType.NOT_LOGGED_IN_ERROR);const h=u.Recovery.fromStorage(this.storage),g=o||h?.type||"openfort",f=n||h?.customToken,p=new u.Recovery(g,f),T=this.shieldAuthentication(p,c,r),m={thirdPartyTokenType:c.thirdPartyTokenType,thirdPartyProvider:c.thirdPartyProvider,accessToken:c.token,playerID:c.player,recovery:T,chainId:e,password:r?.recoveryPassword||null},S={type:"embedded",chainId:e},O=await a.configure(m);return l.storage.save(t.StorageKeys.SIGNER,JSON.stringify(S)),new y.Account(O.accountType,O.address,O.chainId,O.ownerAddress).save(this.storage),new d.EmbeddedSigner(a,m,this.storage)}static shieldAuthentication(e,r,t){let o=null;if("openfort"===e.type)o={auth:a.ShieldAuthType.OPENFORT,authProvider:r.thirdPartyProvider||void 0,token:r.token,tokenType:r.thirdPartyTokenType||void 0,encryptionSession:t?.encryptionSession||void 0},new u.Recovery("openfort").save(this.storage);else if("custom"===e.type){if(!e.customToken)throw new s.OpenfortError("Custom recovery requires a token",s.OpenfortErrorType.INVALID_CONFIGURATION);o={auth:a.ShieldAuthType.CUSTOM,token:e.customToken},new u.Recovery("custom",e.customToken).save(this.storage)}return o}}exports.SignerManager=l;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("../../packages/internal/openapi-clients/dist/index.js"),r=require("./evm/walletHelpers.js"),t=require("./storage/istorage.js"),a=require("./storage/localStorage.js"),n=require("./manager/signer.js"),o=require("./errors/openfortError.js"),i=require("./types.js"),s=require("./configuration/configuration.js"),u=require("./configuration/account.js"),h=require("./configuration/session.js"),g=require("./crypto/key-pair.js"),d=require("./configuration/authentication.js"),c=require("./iframe/iframeManager.js"),l=require("./authManager.js"),p=require("./evm/evmProvider.js");require("./evm/types.js");var f=require("./utils/typedEventEmitter.js"),y=require("./evm/provider/eip6963.js");exports.Openfort=class{storage;provider=null;iAuthManager=null;constructor(e){this.storage=new a.LocalStorage;new s.Configuration(e.baseConfiguration.publishableKey,e.overrides?.backendUrl||"https://api.openfort.xyz",e.shieldConfiguration?.shieldPublishableKey||"",e.shieldConfiguration?.shieldEncryptionKey||"",e.overrides?.shieldUrl||"https://shield.openfort.xyz",e.overrides?.iframeUrl||"https://embedded.openfort.xyz",e.shieldConfiguration?.debug||!1).save()}async logout(){const e=n.SignerManager.fromStorage();this.storage.remove(t.StorageKeys.AUTHENTICATION),this.storage.remove(t.StorageKeys.SIGNER),this.storage.remove(t.StorageKeys.ACCOUNT),e&&await e.logout()}getEthereumProvider(e){const r={announceProvider:!0,...e},t=d.Authentication.fromStorage(this.storage),a=n.SignerManager.fromStorage(),o=u.Account.fromStorage(this.storage);return this.provider?this.provider&&r.policy&&this.provider.updatePolicy(r.policy):(this.provider=new p.EvmProvider({storage:this.storage,openfortEventEmitter:new f,signer:a||void 0,account:o||void 0,authentication:t||void 0,backendApiClients:this.backendApiClients,policyId:r.policy,validateAndRefreshSession:this.validateAndRefreshToken.bind(this)}),r.announceProvider&&y.announceProvider({info:{...y.openfortProviderInfo,...r.providerInfo},provider:this.provider})),this.provider}configureSessionKey(){const e=h.Session.fromStorage(this.storage);if(e)return{address:e.key.getPublicKey(),isRegistered:!0};const r=new g.KeyPair;return new h.Session(r).save(this.storage),{address:r.getPublicKey(),isRegistered:!1}}async configureEmbeddedSigner(e=null,r=null,t=null){await this.validateAndRefreshToken();const a=s.Configuration.fromStorage();let o=null;(t||r?.encryptionSession)&&(o={encryptionSession:r?.encryptionSession||null,recoveryPassword:t||null,encryptionPart:a?.shieldEncryptionKey||null});let i=null,u=null;r&&(i="openfort"===r.auth?"openfort":"custom",u=r.token),await n.SignerManager.embedded(e,o,i,u)}async signMessage(e,r){await this.validateAndRefreshToken();const t=n.SignerManager.fromStorage();if(!t)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);const{hashMessage:a=!0,arrayifyMessage:i=!1}=r||{};return await t.sign(e,i,a)}async signTypedData(e,t,a){await this.validateAndRefreshToken();const i=n.SignerManager.fromStorage(),s=u.Account.fromStorage(this.storage);if(!i||!s)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);return await r.getSignedTypedData({domain:e,types:t,message:a},s.type,Number(s.chainId),i,s.address)}async exportPrivateKey(){await this.validateAndRefreshToken();const e=n.SignerManager.fromStorage();if(!e)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);return await e.export()}async setEmbeddedRecovery({recoveryMethod:e,recoveryPassword:r,encryptionSession:t}){await this.validateAndRefreshToken();const a=n.SignerManager.fromStorage();if(!a)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);if("embedded"!==a.type())throw new o.OpenfortError("Signer must be embedded",o.OpenfortErrorType.INVALID_CONFIGURATION);if("password"===e&&!r)throw new o.OpenfortError("Recovery password is required",o.OpenfortErrorType.INVALID_CONFIGURATION);await a.setEmbeddedRecovery({recoveryMethod:e,recoveryPassword:r,encryptionSession:t})}async logInWithEmailPassword({email:e,password:r,ecosystemGame:t}){const a=d.Authentication.fromStorage(this.storage),n=await this.authManager.loginEmailPassword(e,r,t);return a&&a.player!==n.player.id&&this.logout(),new d.Authentication("jwt",n.token,n.player.id,n.refreshToken).save(this.storage),n}async signUpGuest(){const e=d.Authentication.fromStorage(this.storage),r=await this.authManager.registerGuest();return e&&e.player!==r.player.id&&this.logout(),new d.Authentication("jwt",r.token,r.player.id,r.refreshToken).save(this.storage),r}async signUpWithEmailPassword({email:e,password:r,options:t,ecosystemGame:a}){const n=d.Authentication.fromStorage(this.storage),o=await this.authManager.signupEmailPassword(e,r,t?.data.name,a);return n&&n.player!==o.player.id&&this.logout(),new d.Authentication("jwt",o.token,o.player.id,o.refreshToken).save(this.storage),o}async linkEmailPassword({email:e,password:r,authToken:t,ecosystemGame:a}){return await this.authManager.linkEmail(e,r,t,a)}async unlinkEmailPassword({email:e,authToken:r}){return await this.authManager.unlinkEmail(e,r)}async requestEmailVerification({email:e,redirectUrl:r}){await this.authManager.requestEmailVerification(e,r)}async resetPassword({email:e,password:r,state:t}){await this.authManager.resetPassword(e,r,t)}async requestResetPassword({email:e,redirectUrl:r}){await this.authManager.requestResetPassword(e,r)}async verifyEmail({email:e,state:r}){await this.authManager.verifyEmail(e,r)}async initOAuth({provider:e,options:r,ecosystemGame:a}){return this.storage.remove(t.StorageKeys.AUTHENTICATION),await this.authManager.initOAuth(e,r,a)}async initLinkOAuth({provider:e,options:r,ecosystemGame:t}){const a=d.Authentication.fromStorage(this.storage);if(!a)throw new o.OpenfortError("No authentication found",o.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return await this.authManager.linkOAuth(a,e,r,t)}async linkThirdPartyProvider({provider:e,token:r,tokenType:t}){const a=d.Authentication.fromStorage(this.storage);if(!a)throw new o.OpenfortError("No authentication found",o.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return await this.authManager.linkThirdParty(a,e,r,t)}async unlinkOAuth({provider:e,authToken:r}){return await this.authManager.unlinkOAuth(e,r)}async poolOAuth(e){const r=d.Authentication.fromStorage(this.storage),t=await this.authManager.poolOAuth(e);return r&&r.player!==t.player.id&&this.logout(),new d.Authentication("jwt",t.token,t.player.id,t.refreshToken).save(this.storage),t}async authenticateWithThirdPartyProvider({provider:e,token:r,tokenType:t,ecosystemGame:a}){const o=d.Authentication.fromStorage(this.storage),i=await this.authManager.authenticateThirdParty(e,r,t,a);let s=!1;if(o&&o.player!==i.id&&(this.logout(),s=!0),new d.Authentication("third_party",r,i.id,null,e,t).save(this.storage),s)return i;const u=n.SignerManager.fromStorage();try{await(u?.updateAuthentication())}catch(e){throw(e instanceof c.MissingRecoveryPasswordError||e instanceof c.MissingProjectEntropyError)&&await(u?.logout()),e}return i}async initSIWE({address:e,ecosystemGame:r}){return await this.authManager.initSIWE(e,r)}async authenticateWithSIWE({signature:e,message:r,walletClientType:t,connectorType:a}){const n=d.Authentication.fromStorage(this.storage),o=await this.authManager.authenticateSIWE(e,r,t,a);return n&&n.player!==o.player.id&&this.logout(),new d.Authentication("jwt",o.token,o.player.id,o.refreshToken).save(this.storage),o}async linkWallet({signature:e,message:r,walletClientType:t,connectorType:a,authToken:n}){return await this.authManager.linkWallet(e,r,t,a,n)}async unlinkWallet({address:e,authToken:r}){return await this.authManager.unlinkWallet(e,r)}storeCredentials(e){if(this.storage.remove(t.StorageKeys.AUTHENTICATION),!e.player)throw new o.OpenfortError("Player ID is required to store credentials",o.OpenfortErrorType.INVALID_CONFIGURATION);new d.Authentication("jwt",e.accessToken,e.player,e.refreshToken).save(this.storage)}async sendSignatureTransactionIntentRequest(e,r=null,t=null,a=!1){if(!s.Configuration.fromStorage())throw new o.OpenfortError("Configuration not found",o.OpenfortErrorType.INVALID_CONFIGURATION);await this.validateAndRefreshToken();let i=t;if(!i){if(!r)throw new o.OpenfortError("No signableHash or signature provided",o.OpenfortErrorType.OPERATION_NOT_SUPPORTED_ERROR);const e=n.SignerManager.fromStorage();if(!e)throw new o.OpenfortError("In order to sign a transaction intent, a signer must be configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);i=await e.sign(r)}const u={id:e,signatureRequest:{signature:i,optimistic:a}};return(await this.backendApiClients.transactionIntentsApi.signature(u)).data}async getAccount(){const e=u.Account.fromStorage(this.storage);if(!e)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);return{chainId:e.chainId,address:e.address,ownerAddress:e.ownerAddress,accountType:e.type}}get backendApiClients(){const r=s.Configuration.fromStorage();if(!r)throw new o.OpenfortError("Configuration not found",o.OpenfortErrorType.INVALID_CONFIGURATION);return new e.BackendApiClients({backend:e.createConfig({basePath:r.openfortURL,accessToken:r.publishableKey})})}async sendSignatureSessionRequest(e,r,t){const a={id:e,signatureRequest:{signature:r,optimistic:t}};return(await this.backendApiClients.sessionsApi.signatureSession(a)).data}getEmbeddedState(){if(!d.Authentication.fromStorage(this.storage))return i.EmbeddedState.UNAUTHENTICATED;const e=n.SignerManager.fromStorage();if(!e||"embedded"!==e.type())return i.EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED;return u.Account.fromStorage(this.storage)?i.EmbeddedState.READY:i.EmbeddedState.CREATING_ACCOUNT}getAccessToken(){return d.Authentication.fromStorage(this.storage)?.token??null}get authManager(){if(!this.iAuthManager){const e=s.Configuration.fromStorage();if(!e)throw new o.OpenfortError("Configuration not found",o.OpenfortErrorType.INVALID_CONFIGURATION);this.iAuthManager=new l.AuthManager(e.publishableKey,e.openfortURL)}return this.iAuthManager}async getUser(){await this.validateAndRefreshToken();const e=d.Authentication.fromStorage(this.storage);if(!e)throw new o.OpenfortError("No access token found",o.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return await this.authManager.getUser(e)}async validateAndRefreshToken(e){const r=d.Authentication.fromStorage(this.storage);if(!r)throw new o.OpenfortError("Must be logged in to validate and refresh token",o.OpenfortErrorType.NOT_LOGGED_IN_ERROR);if("jwt"!==r.type)return;const t=await this.authManager.validateCredentials(r,e);if(!t.player)throw new o.OpenfortError("No player found in credentials",o.OpenfortErrorType.INTERNAL_ERROR);if(t.accessToken===r.token)return;new d.Authentication("jwt",t.accessToken,t.player,t.refreshToken).save(this.storage);const a=n.SignerManager.fromStorage();try{await(a?.updateAuthentication())}catch(e){throw(e instanceof c.MissingRecoveryPasswordError||e instanceof c.MissingProjectEntropyError)&&await(a?.logout()),e}}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("../configuration/account.js"),r=require("../configuration/authentication.js"),t=require("../errors/openfortError.js"),a=require("../configuration/recovery.js"),i=require("../iframe/types.js"),o=require("../storage/istorage.js");exports.EmbeddedSigner=class{iframeManager;iframeConfiguration;storage;constructor(e,r,t){this.iframeManager=e,this.iframeConfiguration=r,this.storage=t}async sign(e,r,t){return await this.iframeManager.sign(this.iframeConfiguration,e,r,t)}async export(){return await this.iframeManager.export(this.iframeConfiguration)}async switchChain({chainId:r}){const t=await this.iframeManager.switchChain(this.iframeConfiguration,r);new e.Account(t.accountType,t.address,t.chainId,t.ownerAddress).save(this.storage)}async setEmbeddedRecovery({recoveryMethod:e,recoveryPassword:r,encryptionSession:t}){await this.iframeManager.setEmbeddedRecovery(this.iframeConfiguration,e,r,t)}async logout(){await this.iframeManager.logout(),this.storage.remove(o.StorageKeys.RECOVERY),this.storage.remove(o.StorageKeys.SIGNER)}async updateAuthentication(){const e=r.Authentication.fromStorage(this.storage);if(!e)throw new t.OpenfortError("Must provide authentication to update authentication",t.OpenfortErrorType.NOT_LOGGED_IN_ERROR);const o=a.Recovery.fromStorage(this.storage);if(!o)throw new t.OpenfortError("Must have recovery to update authentication",t.OpenfortErrorType.INVALID_CONFIGURATION);await this.iframeManager.updateAuthentication(this.iframeConfiguration,e.token,"openfort"===o.type?i.ShieldAuthType.OPENFORT:i.ShieldAuthType.CUSTOM)}type(){return"embedded"}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("../storage/istorage.js");exports.SessionSigner=class{sessionKey;storage;constructor(e,s){this.sessionKey=e,this.storage=s}setEmbeddedRecovery(){return Promise.resolve()}async sign(e){return this.sessionKey.sign(e)}async logout(){this.storage.remove(e.StorageKeys.SESSION),this.storage.remove(e.StorageKeys.SIGNER)}updateAuthentication(){return Promise.resolve()}switchChain(){return Promise.resolve()}async export(){return this.sessionKey.getPrivateKey()}type(){return"session"}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var o;exports.StorageKeys=void 0,(o=exports.StorageKeys||(exports.StorageKeys={})).AUTHENTICATION="openfort.authentication",o.SIGNER="openfort.signer",o.CONFIGURATION="openfort.configuration",o.ACCOUNT="openfort.account",o.RECOVERY="openfort.recovery",o.SESSION="openfort.session";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./istorage.js");class a{static validateLocalStorage(){if("undefined"==typeof window||!window.localStorage)throw new Error("Local storage is not available")}get(e){return a.validateLocalStorage(),localStorage.getItem(e)}save(e,o){a.validateLocalStorage(),localStorage.setItem(e,o)}remove(e){a.validateLocalStorage(),localStorage.removeItem(e)}flush(){a.validateLocalStorage();for(const a in e.StorageKeys)localStorage.removeItem(a)}}exports.LocalStorage=a;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,o,t,r,E,A,p,d,s;exports.EmbeddedState=void 0,(e=exports.EmbeddedState||(exports.EmbeddedState={}))[e.NONE=0]="NONE",e[e.UNAUTHENTICATED=1]="UNAUTHENTICATED",e[e.EMBEDDED_SIGNER_NOT_CONFIGURED=2]="EMBEDDED_SIGNER_NOT_CONFIGURED",e[e.CREATING_ACCOUNT=3]="CREATING_ACCOUNT",e[e.READY=4]="READY",exports.OpenfortEvents=void 0,(exports.OpenfortEvents||(exports.OpenfortEvents={})).LOGGED_OUT="loggedOut",exports.RecoveryMethod=void 0,(o=exports.RecoveryMethod||(exports.RecoveryMethod={})).PASSWORD="password",o.AUTOMATIC="automatic",exports.AccountType=void 0,(t=exports.AccountType||(exports.AccountType={})).UPGRADEABLE_V4="Upgradeable_v04",t.MANAGED_V4="Managed_v04",t.ERC6551_V4="ERC6551_v04",t.ERC6551_V5="ERC6551_v05",t.RECOVERABLE_V4="Recoverable_v04",t.MANAGED_V5="Managed_v05",t.UPGRADEABLE_V5="Upgradeable_v05",t.UPGRADEABLE_V6="Upgradeable_v06",t.ZKSYNC_UPGRADEABLE_V1="zksync_upgradeable_v1",t.ZKSYNC_UPGRADEABLE_V2="zksync_upgradeable_v2",exports.AuthType=void 0,(r=exports.AuthType||(exports.AuthType={})).OPENFORT="openfort",r.THIRD_PARTY="thirdParty",exports.TokenType=void 0,(E=exports.TokenType||(exports.TokenType={})).ID_TOKEN="idToken",E.CUSTOM_TOKEN="customToken",exports.ThirdPartyOAuthProvider=void 0,(A=exports.ThirdPartyOAuthProvider||(exports.ThirdPartyOAuthProvider={})).ACCELBYTE="accelbyte",A.FIREBASE="firebase",A.LOOTLOCKER="lootlocker",A.PLAYFAB="playfab",A.SUPABASE="supabase",A.CUSTOM="custom",A.OIDC="oidc",A.TELEGRAM_MINI_APP="telegramMiniApp",exports.BasicAuthProvider=void 0,(p=exports.BasicAuthProvider||(exports.BasicAuthProvider={})).EMAIL="email",p.WALLET="wallet",exports.OAuthProvider=void 0,(d=exports.OAuthProvider||(exports.OAuthProvider={})).GOOGLE="google",d.TWITTER="twitter",d.FACEBOOK="facebook",d.DISCORD="discord",d.EPIC_GAMES="epic_games",d.TELEGRAM="telegram",d.LINE="line",exports.CodeChallengeMethodEnum=void 0,(s=exports.CodeChallengeMethodEnum||(exports.CodeChallengeMethodEnum={})).PLAIN="plain",s.S256="S256";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e="pkce_state",t="pkce_verifier";module.exports=class{savePKCEData(a){localStorage.setItem(e,a.state),localStorage.setItem(t,a.verifier)}getPKCEData(){const a=localStorage.getItem(e),r=localStorage.getItem(t);return a&&r?{state:a,verifier:r}:null}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.isBrowser=()=>"undefined"!=typeof document;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("events");module.exports=class{emitter=new e.EventEmitter;emit(e,...t){this.emitter.emit(e,...t)}on(e,t){this.emitter.on(e,t)}removeListener(e,t){this.emitter.removeListener(e,t)}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.VERSION="0.8.31";
|
package/dist/index.d.ts
CHANGED
|
@@ -472,32 +472,6 @@ declare class SDKConfiguration {
|
|
|
472
472
|
constructor({ baseConfiguration, shieldConfiguration, overrides, }: OpenfortSDKConfiguration);
|
|
473
473
|
}
|
|
474
474
|
|
|
475
|
-
/**
|
|
476
|
-
* ProviderErrors should take priority over RpcErrorCodes
|
|
477
|
-
* https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
478
|
-
* https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
479
|
-
*/
|
|
480
|
-
declare enum ProviderErrorCode {
|
|
481
|
-
USER_REJECTED_REQUEST = 4001,
|
|
482
|
-
UNAUTHORIZED = 4100,
|
|
483
|
-
UNSUPPORTED_METHOD = 4200,
|
|
484
|
-
DISCONNECTED = 4900
|
|
485
|
-
}
|
|
486
|
-
declare enum RpcErrorCode {
|
|
487
|
-
RPC_SERVER_ERROR = -32000,
|
|
488
|
-
INVALID_REQUEST = -32600,
|
|
489
|
-
METHOD_NOT_FOUND = -32601,
|
|
490
|
-
INVALID_PARAMS = -32602,
|
|
491
|
-
INTERNAL_ERROR = -32603,
|
|
492
|
-
PARSE_ERROR = -32700,
|
|
493
|
-
TRANSACTION_REJECTED = -32003
|
|
494
|
-
}
|
|
495
|
-
declare class JsonRpcError extends Error {
|
|
496
|
-
readonly message: string;
|
|
497
|
-
readonly code: ProviderErrorCode | RpcErrorCode;
|
|
498
|
-
constructor(code: ProviderErrorCode | RpcErrorCode, message: string);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
475
|
interface TypedDataPayload {
|
|
502
476
|
types: {
|
|
503
477
|
[K in string]: Array<{
|
|
@@ -524,23 +498,8 @@ interface RequestArguments {
|
|
|
524
498
|
method: string;
|
|
525
499
|
params?: Array<any>;
|
|
526
500
|
}
|
|
527
|
-
type JsonRpcRequestPayload = RequestArguments & {
|
|
528
|
-
jsonrpc?: string;
|
|
529
|
-
id?: string | number;
|
|
530
|
-
};
|
|
531
|
-
interface JsonRpcRequestCallback {
|
|
532
|
-
(err: JsonRpcError | null, result?: JsonRpcResponsePayload | (JsonRpcResponsePayload | null)[] | null): void;
|
|
533
|
-
}
|
|
534
|
-
interface JsonRpcResponsePayload {
|
|
535
|
-
result?: Array<any> | null;
|
|
536
|
-
error?: JsonRpcError | null;
|
|
537
|
-
jsonrpc?: string;
|
|
538
|
-
id?: string | number;
|
|
539
|
-
}
|
|
540
501
|
type Provider = {
|
|
541
502
|
request: (request: RequestArguments) => Promise<any>;
|
|
542
|
-
sendAsync: (request: JsonRpcRequestPayload | JsonRpcRequestPayload[], callback: JsonRpcRequestCallback) => void;
|
|
543
|
-
send: (request: string | JsonRpcRequestPayload | JsonRpcRequestPayload[], callbackOrParams?: JsonRpcRequestCallback | Array<any>, callback?: JsonRpcRequestCallback) => void;
|
|
544
503
|
on: (event: string, listener: (...args: any[]) => void) => void;
|
|
545
504
|
removeListener: (event: string, listener: (...args: any[]) => void) => void;
|
|
546
505
|
isOpenfort: boolean;
|
|
@@ -549,6 +508,7 @@ type Provider = {
|
|
|
549
508
|
declare class Openfort {
|
|
550
509
|
private readonly storage;
|
|
551
510
|
private provider;
|
|
511
|
+
private iAuthManager;
|
|
552
512
|
constructor(sdkConfiguration: OpenfortSDKConfiguration);
|
|
553
513
|
/**
|
|
554
514
|
* Logs the user out by flushing the signer and removing credentials.
|
|
@@ -613,7 +573,7 @@ declare class Openfort {
|
|
|
613
573
|
* @throws {OpenfortError} If no signer is configured.
|
|
614
574
|
*/
|
|
615
575
|
exportPrivateKey(): Promise<string>;
|
|
616
|
-
setEmbeddedRecovery({ recoveryMethod, recoveryPassword, encryptionSession }: {
|
|
576
|
+
setEmbeddedRecovery({ recoveryMethod, recoveryPassword, encryptionSession, }: {
|
|
617
577
|
recoveryMethod: RecoveryMethod;
|
|
618
578
|
recoveryPassword?: string;
|
|
619
579
|
encryptionSession?: string;
|
|
@@ -960,4 +920,9 @@ declare class NotConfiguredError extends Error {
|
|
|
960
920
|
constructor();
|
|
961
921
|
}
|
|
962
922
|
|
|
963
|
-
|
|
923
|
+
/**
|
|
924
|
+
* @deprecated Use named imports instead: `import { Openfort } from '...'`
|
|
925
|
+
*/
|
|
926
|
+
declare const DEPRECATED_OPENFORT: typeof Openfort;
|
|
927
|
+
|
|
928
|
+
export { AuthPlayerResponse, AuthType, BasicAuthProvider, EmbeddedState, InitializeOAuthOptions, MissingProjectEntropyError, MissingRecoveryPasswordError, NotConfiguredError, OAuthProvider, Openfort, OpenfortConfiguration, OpenfortError, OpenfortErrorType, Provider, RecoveryMethod, SDKConfiguration, SDKOverrides, SessionResponse, ShieldAuthOptions, ShieldAuthType, ShieldAuthentication, ShieldConfiguration, ShieldOptions, ThirdPartyOAuthProvider, TokenType, TransactionIntentResponse, TypedDataPayload, WrongRecoveryPasswordError, DEPRECATED_OPENFORT as default };
|