@turnkey/core 1.10.0 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__clients__/core.d.ts +2 -1
- package/dist/__clients__/core.d.ts.map +1 -1
- package/dist/__clients__/core.js +144 -125
- package/dist/__clients__/core.js.map +1 -1
- package/dist/__clients__/core.mjs +144 -125
- package/dist/__clients__/core.mjs.map +1 -1
- package/dist/__generated__/sdk-client-base.d.ts +29 -0
- package/dist/__generated__/sdk-client-base.d.ts.map +1 -1
- package/dist/__generated__/sdk-client-base.js +105 -38
- package/dist/__generated__/sdk-client-base.js.map +1 -1
- package/dist/__generated__/sdk-client-base.mjs +105 -38
- package/dist/__generated__/sdk-client-base.mjs.map +1 -1
- package/dist/__generated__/version.d.ts +1 -1
- package/dist/__generated__/version.js +1 -1
- package/dist/__generated__/version.mjs +1 -1
- package/dist/__stampers__/api/base.d.ts +2 -0
- package/dist/__stampers__/api/base.d.ts.map +1 -1
- package/dist/__stampers__/api/base.js +19 -0
- package/dist/__stampers__/api/base.js.map +1 -1
- package/dist/__stampers__/api/base.mjs +19 -0
- package/dist/__stampers__/api/base.mjs.map +1 -1
- package/dist/__stampers__/api/mobile/stamper.d.ts +2 -0
- package/dist/__stampers__/api/mobile/stamper.d.ts.map +1 -1
- package/dist/__stampers__/api/mobile/stamper.js +19 -0
- package/dist/__stampers__/api/mobile/stamper.js.map +1 -1
- package/dist/__stampers__/api/mobile/stamper.mjs +20 -1
- package/dist/__stampers__/api/mobile/stamper.mjs.map +1 -1
- package/dist/__stampers__/api/web/stamper.d.ts +2 -1
- package/dist/__stampers__/api/web/stamper.d.ts.map +1 -1
- package/dist/__stampers__/api/web/stamper.js +9 -4
- package/dist/__stampers__/api/web/stamper.js.map +1 -1
- package/dist/__stampers__/api/web/stamper.mjs +9 -4
- package/dist/__stampers__/api/web/stamper.mjs.map +1 -1
- package/dist/__storage__/mobile/storage.js +1 -1
- package/dist/__storage__/mobile/storage.js.map +1 -1
- package/dist/__storage__/mobile/storage.mjs +1 -1
- package/dist/__storage__/mobile/storage.mjs.map +1 -1
- package/dist/__types__/auth.d.ts +2 -0
- package/dist/__types__/auth.d.ts.map +1 -1
- package/dist/__types__/auth.js.map +1 -1
- package/dist/__types__/auth.mjs.map +1 -1
- package/dist/__types__/external-wallets.d.ts +9 -1
- package/dist/__types__/external-wallets.d.ts.map +1 -1
- package/dist/__types__/method-types/shared.d.ts +2 -0
- package/dist/__types__/method-types/shared.d.ts.map +1 -1
- package/dist/__wallet__/web/native/ethereum.d.ts.map +1 -1
- package/dist/__wallet__/web/native/ethereum.js +13 -5
- package/dist/__wallet__/web/native/ethereum.js.map +1 -1
- package/dist/__wallet__/web/native/ethereum.mjs +13 -5
- package/dist/__wallet__/web/native/ethereum.mjs.map +1 -1
- package/dist/__wallet__/web/native/solana.d.ts.map +1 -1
- package/dist/__wallet__/web/native/solana.js +17 -9
- package/dist/__wallet__/web/native/solana.js.map +1 -1
- package/dist/__wallet__/web/native/solana.mjs +17 -9
- package/dist/__wallet__/web/native/solana.mjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/utils.d.ts +34 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +103 -9
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +100 -10
- package/dist/utils.mjs.map +1 -1
- package/package.json +8 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TurnkeySDKClientBase } from "../__generated__/sdk-client-base";
|
|
2
|
-
import { type TDeleteSubOrganizationResponse, type Session, type TStampLoginResponse, type v1SignRawPayloadResult, type v1User, type ProxyTGetWalletKitConfigResponse, type v1PrivateKey, type WalletAuthResult, type BaseAuthResult,
|
|
2
|
+
import { type TDeleteSubOrganizationResponse, type Session, type TStampLoginResponse, type v1SignRawPayloadResult, type v1User, type ProxyTGetWalletKitConfigResponse, type v1PrivateKey, type WalletAuthResult, type BaseAuthResult, type PasskeyAuthResult, type v1BootProof, type TGetSendTransactionStatusResponse, AuthAction } from "@turnkey/sdk-types";
|
|
3
3
|
import { Chain, type ExportBundle, type TurnkeySDKClientConfig, type WalletAccount, type Wallet, type WalletManagerBase, type WalletProvider, type CreatePasskeyParams, type CreatePasskeyResult, type LogoutParams, type LoginWithPasskeyParams, type SignUpWithPasskeyParams, type SwitchWalletAccountChainParams, type LoginWithWalletParams, type SignUpWithWalletParams, type LoginOrSignupWithWalletParams, type InitOtpParams, type VerifyOtpParams, type VerifyOtpResult, type LoginWithOtpParams, type SignUpWithOtpParams, type CompleteOtpParams, type CompleteOauthParams, type LoginWithOauthParams, type SignUpWithOauthParams, type FetchWalletsParams, type FetchWalletAccountsParams, type FetchPrivateKeysParams, type SignMessageParams, type SignTransactionParams, type SignAndSendTransactionParams, type EthSendTransactionParams, type FetchUserParams, type FetchOrCreateP256ApiKeyUserParams, type FetchOrCreatePoliciesParams, type FetchOrCreatePoliciesResult, type UpdateUserEmailParams, type RemoveUserEmailParams, type UpdateUserPhoneNumberParams, type RemoveUserPhoneNumberParams, type UpdateUserNameParams, type AddOauthProviderParams, type RemoveOauthProvidersParams, type AddPasskeyParams, type RemovePasskeyParams, type CreateWalletParams, type CreateWalletAccountsParams, type ExportWalletParams, type ExportPrivateKeyParams, type ExportWalletAccountParams, type ImportWalletParams, type ImportPrivateKeyParams, type DeleteSubOrganizationParams, type StoreSessionParams, type ClearSessionParams, type RefreshSessionParams, type GetSessionParams, type SetActiveSessionParams, type CreateApiKeyPairParams, type FetchBootProofForAppProofParams, type CreateHttpClientParams, type BuildWalletLoginRequestResult, type BuildWalletLoginRequestParams, type VerifyAppProofsParams, type PollTransactionStatusParams } from "../__types__";
|
|
4
4
|
import { CrossPlatformApiKeyStamper } from "../__stampers__/api/base";
|
|
5
5
|
import { CrossPlatformPasskeyStamper } from "../__stampers__/passkey/base";
|
|
@@ -267,6 +267,7 @@ export declare class TurnkeyClient {
|
|
|
267
267
|
* @param params.otpCode - OTP code entered by the user.
|
|
268
268
|
* @param params.contact - contact information for the user (e.g., email address or phone number).
|
|
269
269
|
* @param params.otpType - type of OTP being verified (OtpType.Email or OtpType.Sms).
|
|
270
|
+
* @param params.publicKey - public key the verification token is bound to for ownership verification (client signature verification during login/signup). This public key is optional; if not provided, a new key pair will be generated.
|
|
270
271
|
* @returns A promise that resolves to an object containing:
|
|
271
272
|
* - subOrganizationId: sub-organization ID if the contact is already associated with a sub-organization, or an empty string if not.
|
|
272
273
|
* - verificationToken: verification token to be used for login or sign-up.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/__clients__/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EACL,KAAK,8BAA8B,EACnC,KAAK,OAAO,EACZ,KAAK,mBAAmB,EAExB,KAAK,sBAAsB,EAC3B,KAAK,MAAM,
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/__clients__/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EACL,KAAK,8BAA8B,EACnC,KAAK,OAAO,EACZ,KAAK,mBAAmB,EAExB,KAAK,sBAAsB,EAC3B,KAAK,MAAM,EACX,KAAK,gCAAgC,EAErC,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EAEtB,KAAK,WAAW,EAEhB,KAAK,iCAAiC,EAOtC,UAAU,EACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAML,KAAK,EAKL,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAClB,KAAK,MAAM,EAMX,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAGnB,KAAK,mBAAmB,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AAmB,QAAa,QAAQ,MAAM,GAAG,SAAS,CAAC,CAUzD;IAEF;;;;;;;;;;OAUG;IACH,mBAAmB,QAAa,QAAQ,IAAI,CAAC,CAoC3C;IAEF;;;;;;;;;;;;;OAaG;IACH,gBAAgB,YACL,sBAAsB,KAC9B,QAAQ,MAAM,CAAC,CA2BhB;IAEF;;;;;;;;;;OAUG;IACH,kBAAkB,QAAa,QAAQ,gCAAgC,CAAC,CAmBtE;IAEF;;;;;;;;;;;;;OAaG;IACH,yBAAyB,WACf,+BAA+B,KACtC,QAAQ,WAAW,CAAC,CAoDrB;IAEF;;;;;;;;;;OAUG;IACH,eAAe,WAAkB,qBAAqB,KAAG,QAAQ,IAAI,CAAC,CA+DpE;CACH"}
|
package/dist/__clients__/core.js
CHANGED
|
@@ -13,11 +13,12 @@ var jwtDecode = require('jwt-decode');
|
|
|
13
13
|
var base$3 = require('../__wallet__/base.js');
|
|
14
14
|
var ethers = require('ethers');
|
|
15
15
|
var crypto = require('@turnkey/crypto');
|
|
16
|
+
var apiKeyStamper = require('@turnkey/api-key-stamper');
|
|
16
17
|
|
|
17
18
|
class TurnkeyClient {
|
|
18
19
|
constructor(config,
|
|
19
20
|
// Users can pass in their own stampers, or we will create them. Should we remove this?
|
|
20
|
-
apiKeyStamper, passkeyStamper, walletManager) {
|
|
21
|
+
apiKeyStamper$1, passkeyStamper, walletManager) {
|
|
21
22
|
/**
|
|
22
23
|
* Creates a new TurnkeySDKClientBase instance with the provided configuration.
|
|
23
24
|
* This method is used internally to create the HTTP client for making API requests,
|
|
@@ -489,28 +490,12 @@ class TurnkeyClient {
|
|
|
489
490
|
if (!signedRequest) {
|
|
490
491
|
throw new sdkTypes.TurnkeyError("Failed to create stamped request for wallet login", sdkTypes.TurnkeyErrorCodes.BAD_RESPONSE);
|
|
491
492
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
// for Ethereum, there is no way to get the public key from the wallet address
|
|
496
|
-
// so we derive it from the signed request
|
|
497
|
-
publicKey = utils.getPublicKeyFromStampHeader(signedRequest.stamp.stampHeaderValue);
|
|
498
|
-
break;
|
|
499
|
-
}
|
|
500
|
-
case enums.Chain.Solana: {
|
|
501
|
-
// for Solana, we can get the public key from the wallet address
|
|
502
|
-
// since the wallet address is the public key
|
|
503
|
-
// this doesn't require any action from the user as long as the wallet is connected
|
|
504
|
-
// which it has to be since they just called stampStampLogin()
|
|
505
|
-
publicKey = await this.walletManager.stamper.getPublicKey(walletProvider.interfaceType, walletProvider);
|
|
506
|
-
break;
|
|
507
|
-
}
|
|
508
|
-
default:
|
|
509
|
-
throw new sdkTypes.TurnkeyError(`Unsupported interface type: ${walletProvider.interfaceType}`, sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
510
|
-
}
|
|
493
|
+
// the wallet's public key is embedded in the stamp header by the wallet stamper
|
|
494
|
+
// so we extract it from there
|
|
495
|
+
const publicKey = utils.getPublicKeyFromStampHeader(signedRequest.stamp.stampHeaderValue);
|
|
511
496
|
return {
|
|
512
497
|
signedRequest,
|
|
513
|
-
publicKey
|
|
498
|
+
publicKey,
|
|
514
499
|
};
|
|
515
500
|
}, {
|
|
516
501
|
errorCode: sdkTypes.TurnkeyErrorCodes.WALLET_BUILD_LOGIN_REQUEST_ERROR,
|
|
@@ -547,49 +532,25 @@ class TurnkeyClient {
|
|
|
547
532
|
* @throws {TurnkeyError} If the wallet stamper is uninitialized, a public key cannot be found or generated, or login fails.
|
|
548
533
|
*/
|
|
549
534
|
this.loginWithWallet = async (params) => {
|
|
550
|
-
|
|
535
|
+
const { walletProvider, sessionKey = enums.SessionKey.DefaultSessionkey } = params;
|
|
551
536
|
return utils.withTurnkeyErrorHandling(async () => {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const expirationSeconds = params?.expirationSeconds || auth.DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
|
|
558
|
-
if (!generatedPublicKey) {
|
|
559
|
-
throw new sdkTypes.TurnkeyError("A publickey could not be found or generated.", sdkTypes.TurnkeyErrorCodes.INTERNAL_ERROR);
|
|
537
|
+
const { signedRequest, publicKey } = await this.buildWalletLoginRequest(params);
|
|
538
|
+
const sessionResponse = await this.httpClient.sendSignedRequest(signedRequest);
|
|
539
|
+
const sessionToken = sessionResponse.session;
|
|
540
|
+
if (!sessionToken) {
|
|
541
|
+
throw new sdkTypes.TurnkeyError("Session token not found in the response", sdkTypes.TurnkeyErrorCodes.BAD_RESPONSE);
|
|
560
542
|
}
|
|
561
|
-
this.walletManager.stamper.setProvider(walletProvider.interfaceType, walletProvider);
|
|
562
|
-
const sessionResponse = await this.httpClient.stampLogin({
|
|
563
|
-
publicKey: generatedPublicKey,
|
|
564
|
-
organizationId: params?.organizationId ?? this.config.organizationId,
|
|
565
|
-
expirationSeconds,
|
|
566
|
-
}, enums.StamperType.Wallet);
|
|
567
543
|
await this.storeSession({
|
|
568
544
|
sessionToken: sessionResponse.session,
|
|
569
545
|
sessionKey,
|
|
570
546
|
});
|
|
571
|
-
// TODO (Moe): What happens if a user connects to MetaMask on Ethereum,
|
|
572
|
-
// then switches to a Solana account within MetaMask? Will this flow break?
|
|
573
|
-
const address = utils.addressFromPublicKey(walletProvider.chainInfo.namespace, generatedPublicKey);
|
|
574
|
-
generatedPublicKey = undefined; // Key pair was successfully used, set to null to prevent cleanup
|
|
575
547
|
return {
|
|
576
548
|
sessionToken: sessionResponse.session,
|
|
577
|
-
address,
|
|
549
|
+
address: utils.addressFromPublicKey(walletProvider.chainInfo.namespace, publicKey),
|
|
578
550
|
};
|
|
579
551
|
}, {
|
|
580
552
|
errorMessage: "Unable to log in with the provided wallet",
|
|
581
553
|
errorCode: sdkTypes.TurnkeyErrorCodes.WALLET_LOGIN_AUTH_ERROR,
|
|
582
|
-
}, {
|
|
583
|
-
finallyFn: async () => {
|
|
584
|
-
if (generatedPublicKey) {
|
|
585
|
-
try {
|
|
586
|
-
await this.apiKeyStamper?.deleteKeyPair(generatedPublicKey);
|
|
587
|
-
}
|
|
588
|
-
catch (cleanupError) {
|
|
589
|
-
throw new sdkTypes.TurnkeyError("Failed to clean up generated key pair", sdkTypes.TurnkeyErrorCodes.KEY_PAIR_CLEANUP_ERROR, cleanupError);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
},
|
|
593
554
|
});
|
|
594
555
|
};
|
|
595
556
|
/**
|
|
@@ -612,18 +573,9 @@ class TurnkeyClient {
|
|
|
612
573
|
* @throws {TurnkeyError} If there is an error during wallet authentication, sub-organization creation, session storage, or cleanup.
|
|
613
574
|
*/
|
|
614
575
|
this.signUpWithWallet = async (params) => {
|
|
615
|
-
const { walletProvider, createSubOrgParams, sessionKey = enums.SessionKey.DefaultSessionkey,
|
|
616
|
-
let generatedPublicKey = undefined;
|
|
576
|
+
const { walletProvider, createSubOrgParams, sessionKey = enums.SessionKey.DefaultSessionkey, } = params;
|
|
617
577
|
return utils.withTurnkeyErrorHandling(async () => {
|
|
618
|
-
|
|
619
|
-
throw new sdkTypes.TurnkeyError("Wallet stamper is not initialized", sdkTypes.TurnkeyErrorCodes.WALLET_MANAGER_COMPONENT_NOT_INITIALIZED);
|
|
620
|
-
}
|
|
621
|
-
generatedPublicKey = await this.apiKeyStamper?.createKeyPair();
|
|
622
|
-
this.walletManager.stamper.setProvider(walletProvider.interfaceType, walletProvider);
|
|
623
|
-
const publicKey = await this.walletManager.stamper.getPublicKey(walletProvider.interfaceType, walletProvider);
|
|
624
|
-
if (!publicKey) {
|
|
625
|
-
throw new sdkTypes.TurnkeyError("Failed to get public key from wallet", sdkTypes.TurnkeyErrorCodes.WALLET_SIGNUP_AUTH_ERROR);
|
|
626
|
-
}
|
|
578
|
+
const { signedRequest, publicKey } = await this.buildWalletLoginRequest(params);
|
|
627
579
|
const signUpBody = utils.buildSignUpBody({
|
|
628
580
|
createSubOrgParams: {
|
|
629
581
|
...createSubOrgParams,
|
|
@@ -633,12 +585,6 @@ class TurnkeyClient {
|
|
|
633
585
|
publicKey: publicKey,
|
|
634
586
|
curveType: utils.getCurveTypeFromProvider(walletProvider),
|
|
635
587
|
},
|
|
636
|
-
{
|
|
637
|
-
apiKeyName: `wallet-auth-${generatedPublicKey}`,
|
|
638
|
-
publicKey: generatedPublicKey,
|
|
639
|
-
curveType: "API_KEY_CURVE_P256",
|
|
640
|
-
expirationSeconds: "60",
|
|
641
|
-
},
|
|
642
588
|
],
|
|
643
589
|
},
|
|
644
590
|
});
|
|
@@ -646,43 +592,24 @@ class TurnkeyClient {
|
|
|
646
592
|
if (!res) {
|
|
647
593
|
throw new sdkTypes.TurnkeyError(`Sign up failed`, sdkTypes.TurnkeyErrorCodes.WALLET_SIGNUP_AUTH_ERROR);
|
|
648
594
|
}
|
|
649
|
-
|
|
650
|
-
this.
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
595
|
+
// now we can send the stamped request to Turnkey
|
|
596
|
+
const sessionResponse = await this.httpClient.sendSignedRequest(signedRequest);
|
|
597
|
+
const sessionToken = sessionResponse.session;
|
|
598
|
+
if (!sessionToken) {
|
|
599
|
+
throw new sdkTypes.TurnkeyError("Session token not found in the response", sdkTypes.TurnkeyErrorCodes.BAD_RESPONSE);
|
|
600
|
+
}
|
|
601
|
+
await this.storeSession({
|
|
602
|
+
sessionToken: sessionToken,
|
|
603
|
+
sessionKey,
|
|
655
604
|
});
|
|
656
|
-
await Promise.all([
|
|
657
|
-
this.apiKeyStamper?.deleteKeyPair(generatedPublicKey),
|
|
658
|
-
this.storeSession({
|
|
659
|
-
sessionToken: sessionResponse.session,
|
|
660
|
-
sessionKey,
|
|
661
|
-
}),
|
|
662
|
-
]);
|
|
663
|
-
generatedPublicKey = undefined; // Key pair was successfully used, set to null to prevent cleanup
|
|
664
|
-
// TODO (Moe): What happens if a user connects to MetaMask on Ethereum,
|
|
665
|
-
// then switches to a Solana account within MetaMask? Will this flow break?
|
|
666
605
|
return {
|
|
667
|
-
sessionToken:
|
|
606
|
+
sessionToken: sessionToken,
|
|
668
607
|
appProofs: res.appProofs,
|
|
669
608
|
address: utils.addressFromPublicKey(walletProvider.chainInfo.namespace, publicKey),
|
|
670
609
|
};
|
|
671
610
|
}, {
|
|
672
611
|
errorMessage: "Failed to sign up with wallet",
|
|
673
612
|
errorCode: sdkTypes.TurnkeyErrorCodes.WALLET_SIGNUP_AUTH_ERROR,
|
|
674
|
-
}, {
|
|
675
|
-
finallyFn: async () => {
|
|
676
|
-
this.apiKeyStamper?.clearTemporaryPublicKey();
|
|
677
|
-
if (generatedPublicKey) {
|
|
678
|
-
try {
|
|
679
|
-
await this.apiKeyStamper?.deleteKeyPair(generatedPublicKey);
|
|
680
|
-
}
|
|
681
|
-
catch (cleanupError) {
|
|
682
|
-
throw new sdkTypes.TurnkeyError("Failed to clean up generated key pair", sdkTypes.TurnkeyErrorCodes.KEY_PAIR_CLEANUP_ERROR, cleanupError);
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
},
|
|
686
613
|
});
|
|
687
614
|
};
|
|
688
615
|
/**
|
|
@@ -708,9 +635,7 @@ class TurnkeyClient {
|
|
|
708
635
|
* @throws {TurnkeyError} If there is an error during wallet authentication, sub-organization creation, or session storage.
|
|
709
636
|
*/
|
|
710
637
|
this.loginOrSignupWithWallet = async (params) => {
|
|
711
|
-
const createSubOrgParams = params
|
|
712
|
-
const sessionKey = params.sessionKey || enums.SessionKey.DefaultSessionkey;
|
|
713
|
-
const walletProvider = params.walletProvider;
|
|
638
|
+
const { walletProvider, createSubOrgParams, sessionKey = enums.SessionKey.DefaultSessionkey, } = params;
|
|
714
639
|
return utils.withTurnkeyErrorHandling(async () => {
|
|
715
640
|
const { signedRequest, publicKey } = await this.buildWalletLoginRequest(params);
|
|
716
641
|
// here we check if the subOrg exists and create one
|
|
@@ -744,8 +669,8 @@ class TurnkeyClient {
|
|
|
744
669
|
}
|
|
745
670
|
}
|
|
746
671
|
// now we can send the stamped request to Turnkey
|
|
747
|
-
const sessionResponse = await
|
|
748
|
-
const sessionToken = sessionResponse.
|
|
672
|
+
const sessionResponse = await this.httpClient.sendSignedRequest(signedRequest);
|
|
673
|
+
const sessionToken = sessionResponse.session;
|
|
749
674
|
if (!sessionToken) {
|
|
750
675
|
throw new sdkTypes.TurnkeyError("Session token not found in the response", sdkTypes.TurnkeyErrorCodes.BAD_RESPONSE);
|
|
751
676
|
}
|
|
@@ -763,8 +688,6 @@ class TurnkeyClient {
|
|
|
763
688
|
}, {
|
|
764
689
|
errorCode: sdkTypes.TurnkeyErrorCodes.WALLET_LOGIN_OR_SIGNUP_ERROR,
|
|
765
690
|
errorMessage: "Failed to log in or sign up with wallet",
|
|
766
|
-
catchFn: async () => {
|
|
767
|
-
},
|
|
768
691
|
});
|
|
769
692
|
};
|
|
770
693
|
/**
|
|
@@ -810,6 +733,7 @@ class TurnkeyClient {
|
|
|
810
733
|
* @param params.otpCode - OTP code entered by the user.
|
|
811
734
|
* @param params.contact - contact information for the user (e.g., email address or phone number).
|
|
812
735
|
* @param params.otpType - type of OTP being verified (OtpType.Email or OtpType.Sms).
|
|
736
|
+
* @param params.publicKey - public key the verification token is bound to for ownership verification (client signature verification during login/signup). This public key is optional; if not provided, a new key pair will be generated.
|
|
813
737
|
* @returns A promise that resolves to an object containing:
|
|
814
738
|
* - subOrganizationId: sub-organization ID if the contact is already associated with a sub-organization, or an empty string if not.
|
|
815
739
|
* - verificationToken: verification token to be used for login or sign-up.
|
|
@@ -817,10 +741,12 @@ class TurnkeyClient {
|
|
|
817
741
|
*/
|
|
818
742
|
this.verifyOtp = async (params) => {
|
|
819
743
|
const { otpId, otpCode, contact, otpType } = params;
|
|
744
|
+
const resolvedPublicKey = params.publicKey ?? (await this.apiKeyStamper?.createKeyPair());
|
|
820
745
|
return utils.withTurnkeyErrorHandling(async () => {
|
|
821
746
|
const verifyOtpRes = await this.httpClient.proxyVerifyOtp({
|
|
822
747
|
otpId: otpId,
|
|
823
748
|
otpCode: otpCode,
|
|
749
|
+
publicKey: resolvedPublicKey,
|
|
824
750
|
});
|
|
825
751
|
if (!verifyOtpRes) {
|
|
826
752
|
throw new sdkTypes.TurnkeyError(`OTP verification failed`, sdkTypes.TurnkeyErrorCodes.INTERNAL_ERROR);
|
|
@@ -828,6 +754,7 @@ class TurnkeyClient {
|
|
|
828
754
|
const accountRes = await this.httpClient.proxyGetAccount({
|
|
829
755
|
filterType: enums.OtpTypeToFilterTypeMap[otpType],
|
|
830
756
|
filterValue: contact,
|
|
757
|
+
verificationToken: verifyOtpRes.verificationToken,
|
|
831
758
|
});
|
|
832
759
|
if (!accountRes) {
|
|
833
760
|
throw new sdkTypes.TurnkeyError(`Account fetch failed`, sdkTypes.TurnkeyErrorCodes.ACCOUNT_FETCH_ERROR);
|
|
@@ -869,10 +796,26 @@ class TurnkeyClient {
|
|
|
869
796
|
this.loginWithOtp = async (params) => {
|
|
870
797
|
const { verificationToken, invalidateExisting = false, publicKey = await this.apiKeyStamper?.createKeyPair(), organizationId, sessionKey = enums.SessionKey.DefaultSessionkey, } = params;
|
|
871
798
|
return utils.withTurnkeyErrorHandling(async () => {
|
|
799
|
+
const { message, publicKey: clientSignaturePublicKey } = utils.getClientSignatureMessageForLogin({
|
|
800
|
+
verificationToken,
|
|
801
|
+
sessionPublicKey: publicKey,
|
|
802
|
+
});
|
|
803
|
+
this.apiKeyStamper?.setTemporaryPublicKey(publicKey);
|
|
804
|
+
const signature = await this.apiKeyStamper?.sign(message, apiKeyStamper.SignatureFormat.Raw);
|
|
805
|
+
if (!signature) {
|
|
806
|
+
throw new sdkTypes.TurnkeyError(`Failed to sign client signature for OTP login`, sdkTypes.TurnkeyErrorCodes.INTERNAL_ERROR);
|
|
807
|
+
}
|
|
808
|
+
const clientSignature = {
|
|
809
|
+
message: message,
|
|
810
|
+
publicKey: clientSignaturePublicKey,
|
|
811
|
+
scheme: "CLIENT_SIGNATURE_SCHEME_API_P256",
|
|
812
|
+
signature: signature,
|
|
813
|
+
};
|
|
872
814
|
const res = await this.httpClient.proxyOtpLogin({
|
|
873
815
|
verificationToken,
|
|
874
816
|
publicKey: publicKey,
|
|
875
817
|
invalidateExisting,
|
|
818
|
+
clientSignature,
|
|
876
819
|
...(organizationId && { organizationId }),
|
|
877
820
|
});
|
|
878
821
|
if (!res) {
|
|
@@ -903,6 +846,10 @@ class TurnkeyClient {
|
|
|
903
846
|
}
|
|
904
847
|
}
|
|
905
848
|
},
|
|
849
|
+
}, {
|
|
850
|
+
finallyFn: async () => {
|
|
851
|
+
this.apiKeyStamper?.clearTemporaryPublicKey();
|
|
852
|
+
},
|
|
906
853
|
});
|
|
907
854
|
};
|
|
908
855
|
/**
|
|
@@ -925,7 +872,8 @@ class TurnkeyClient {
|
|
|
925
872
|
* @throws {TurnkeyError} If there is an error during the OTP sign-up process or session storage.
|
|
926
873
|
*/
|
|
927
874
|
this.signUpWithOtp = async (params) => {
|
|
928
|
-
const { verificationToken, contact, otpType, createSubOrgParams, invalidateExisting, sessionKey, } = params;
|
|
875
|
+
const { verificationToken, contact, otpType, createSubOrgParams, invalidateExisting, sessionKey, publicKey = await this.apiKeyStamper?.createKeyPair(), } = params;
|
|
876
|
+
// build sign up body without client signature first
|
|
929
877
|
const signUpBody = utils.buildSignUpBody({
|
|
930
878
|
createSubOrgParams: {
|
|
931
879
|
...createSubOrgParams,
|
|
@@ -936,14 +884,37 @@ class TurnkeyClient {
|
|
|
936
884
|
},
|
|
937
885
|
});
|
|
938
886
|
return utils.withTurnkeyErrorHandling(async () => {
|
|
939
|
-
const
|
|
940
|
-
|
|
887
|
+
const { message, publicKey: clientSignaturePublicKey } = utils.getClientSignatureMessageForSignup({
|
|
888
|
+
verificationToken,
|
|
889
|
+
...(signUpBody.userEmail && { email: signUpBody.userEmail }),
|
|
890
|
+
...(signUpBody.userPhoneNumber && {
|
|
891
|
+
phoneNumber: signUpBody.userPhoneNumber,
|
|
892
|
+
}),
|
|
893
|
+
apiKeys: signUpBody.apiKeys,
|
|
894
|
+
authenticators: signUpBody.authenticators,
|
|
895
|
+
oauthProviders: signUpBody.oauthProviders,
|
|
896
|
+
});
|
|
897
|
+
this.apiKeyStamper?.setTemporaryPublicKey(publicKey);
|
|
898
|
+
const signature = await this.apiKeyStamper?.sign(message, apiKeyStamper.SignatureFormat.Raw);
|
|
899
|
+
if (!signature) {
|
|
900
|
+
throw new sdkTypes.TurnkeyError(`Failed to sign client signature for OTP sign up`, sdkTypes.TurnkeyErrorCodes.INTERNAL_ERROR);
|
|
901
|
+
}
|
|
902
|
+
const clientSignature = {
|
|
903
|
+
message: message,
|
|
904
|
+
publicKey: clientSignaturePublicKey,
|
|
905
|
+
scheme: "CLIENT_SIGNATURE_SCHEME_API_P256",
|
|
906
|
+
signature: signature,
|
|
907
|
+
};
|
|
908
|
+
const signupRes = await this.httpClient.proxySignup({
|
|
909
|
+
...signUpBody,
|
|
910
|
+
clientSignature,
|
|
911
|
+
});
|
|
941
912
|
if (!signupRes) {
|
|
942
913
|
throw new sdkTypes.TurnkeyError(`Auth proxy OTP sign up failed`, sdkTypes.TurnkeyErrorCodes.OTP_SIGNUP_ERROR);
|
|
943
914
|
}
|
|
944
915
|
const otpRes = await this.loginWithOtp({
|
|
945
916
|
verificationToken,
|
|
946
|
-
publicKey:
|
|
917
|
+
publicKey: publicKey,
|
|
947
918
|
...(invalidateExisting && { invalidateExisting }),
|
|
948
919
|
...(sessionKey && { sessionKey }),
|
|
949
920
|
});
|
|
@@ -952,8 +923,23 @@ class TurnkeyClient {
|
|
|
952
923
|
appProofs: signupRes.appProofs,
|
|
953
924
|
};
|
|
954
925
|
}, {
|
|
926
|
+
catchFn: async () => {
|
|
927
|
+
// Clean up the generated key pair if it wasn't successfully used
|
|
928
|
+
if (publicKey) {
|
|
929
|
+
try {
|
|
930
|
+
await this.apiKeyStamper?.deleteKeyPair(publicKey);
|
|
931
|
+
}
|
|
932
|
+
catch (cleanupError) {
|
|
933
|
+
throw new sdkTypes.TurnkeyError(`Failed to clean up generated key pair`, sdkTypes.TurnkeyErrorCodes.KEY_PAIR_CLEANUP_ERROR, cleanupError);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
},
|
|
955
937
|
errorCode: sdkTypes.TurnkeyErrorCodes.OTP_SIGNUP_ERROR,
|
|
956
938
|
errorMessage: "Failed to sign up with OTP",
|
|
939
|
+
}, {
|
|
940
|
+
finallyFn: async () => {
|
|
941
|
+
this.apiKeyStamper?.clearTemporaryPublicKey();
|
|
942
|
+
},
|
|
957
943
|
});
|
|
958
944
|
};
|
|
959
945
|
/**
|
|
@@ -980,13 +966,14 @@ class TurnkeyClient {
|
|
|
980
966
|
* @throws {TurnkeyError} If there is an error during OTP verification, sign-up, or login.
|
|
981
967
|
*/
|
|
982
968
|
this.completeOtp = async (params) => {
|
|
983
|
-
const { otpId, otpCode, contact, otpType, publicKey, invalidateExisting = false, sessionKey, createSubOrgParams, } = params;
|
|
969
|
+
const { otpId, otpCode, contact, otpType, publicKey = await this.apiKeyStamper?.createKeyPair(), invalidateExisting = false, sessionKey, createSubOrgParams, } = params;
|
|
984
970
|
return utils.withTurnkeyErrorHandling(async () => {
|
|
985
971
|
const { subOrganizationId, verificationToken } = await this.verifyOtp({
|
|
986
972
|
otpId: otpId,
|
|
987
973
|
otpCode: otpCode,
|
|
988
974
|
contact: contact,
|
|
989
975
|
otpType: otpType,
|
|
976
|
+
publicKey: publicKey,
|
|
990
977
|
});
|
|
991
978
|
if (!verificationToken) {
|
|
992
979
|
throw new sdkTypes.TurnkeyError("No verification token returned from OTP verification", sdkTypes.TurnkeyErrorCodes.VERIFY_OTP_ERROR);
|
|
@@ -999,6 +986,7 @@ class TurnkeyClient {
|
|
|
999
986
|
...(createSubOrgParams && { createSubOrgParams }),
|
|
1000
987
|
...(invalidateExisting && { invalidateExisting }),
|
|
1001
988
|
...(sessionKey && { sessionKey }),
|
|
989
|
+
publicKey: publicKey,
|
|
1002
990
|
});
|
|
1003
991
|
return {
|
|
1004
992
|
...signUpRes,
|
|
@@ -1009,7 +997,7 @@ class TurnkeyClient {
|
|
|
1009
997
|
else {
|
|
1010
998
|
const loginRes = await this.loginWithOtp({
|
|
1011
999
|
verificationToken,
|
|
1012
|
-
|
|
1000
|
+
publicKey: publicKey,
|
|
1013
1001
|
...(invalidateExisting && { invalidateExisting }),
|
|
1014
1002
|
...(sessionKey && { sessionKey }),
|
|
1015
1003
|
});
|
|
@@ -1247,7 +1235,9 @@ class TurnkeyClient {
|
|
|
1247
1235
|
if (!signedUserRequest) {
|
|
1248
1236
|
throw new sdkTypes.TurnkeyError("Failed to stamp user request", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
1249
1237
|
}
|
|
1250
|
-
userPromise =
|
|
1238
|
+
userPromise = this.httpClient
|
|
1239
|
+
.sendSignedRequest(signedUserRequest)
|
|
1240
|
+
.then((response) => utils.getAuthenticatorAddresses(response.user));
|
|
1251
1241
|
}
|
|
1252
1242
|
// if connectedOnly is true, we skip fetching embedded wallets
|
|
1253
1243
|
if (!connectedOnly) {
|
|
@@ -1267,7 +1257,7 @@ class TurnkeyClient {
|
|
|
1267
1257
|
}
|
|
1268
1258
|
const [accounts, walletsRes] = await Promise.all([
|
|
1269
1259
|
utils.fetchAllWalletAccountsWithCursor(this.httpClient, organizationId, stampWith),
|
|
1270
|
-
|
|
1260
|
+
this.httpClient.sendSignedRequest(signedWalletsRequest),
|
|
1271
1261
|
]);
|
|
1272
1262
|
// create a map of walletId to EmbeddedWallet for easy lookup
|
|
1273
1263
|
const walletMap = new Map(walletsRes.wallets.map((wallet) => [
|
|
@@ -2062,12 +2052,15 @@ class TurnkeyClient {
|
|
|
2062
2052
|
throw new sdkTypes.TurnkeyError("User ID must be provided to update user email", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2063
2053
|
}
|
|
2064
2054
|
return utils.withTurnkeyErrorHandling(async () => {
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2055
|
+
if (verificationToken) {
|
|
2056
|
+
const existingUser = await this.httpClient.proxyGetAccount({
|
|
2057
|
+
filterType: enums.FilterType.Email,
|
|
2058
|
+
filterValue: email,
|
|
2059
|
+
verificationToken,
|
|
2060
|
+
});
|
|
2061
|
+
if (existingUser.organizationId) {
|
|
2062
|
+
throw new sdkTypes.TurnkeyError(`Email ${email} is already associated with another user.`, sdkTypes.TurnkeyErrorCodes.ACCOUNT_ALREADY_EXISTS);
|
|
2063
|
+
}
|
|
2071
2064
|
}
|
|
2072
2065
|
const res = await this.httpClient.updateUserEmail({
|
|
2073
2066
|
userId: userId,
|
|
@@ -2145,6 +2138,16 @@ class TurnkeyClient {
|
|
|
2145
2138
|
throw new sdkTypes.TurnkeyError("User ID must be provided to update user phone number", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2146
2139
|
}
|
|
2147
2140
|
return utils.withTurnkeyErrorHandling(async () => {
|
|
2141
|
+
if (verificationToken) {
|
|
2142
|
+
const existingUser = await this.httpClient.proxyGetAccount({
|
|
2143
|
+
filterType: enums.FilterType.Sms,
|
|
2144
|
+
filterValue: phoneNumber,
|
|
2145
|
+
verificationToken,
|
|
2146
|
+
});
|
|
2147
|
+
if (existingUser.organizationId) {
|
|
2148
|
+
throw new sdkTypes.TurnkeyError(`Phone number ${phoneNumber} is already associated with another user.`, sdkTypes.TurnkeyErrorCodes.ACCOUNT_ALREADY_EXISTS);
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2148
2151
|
const res = await this.httpClient.updateUserPhoneNumber({
|
|
2149
2152
|
userId,
|
|
2150
2153
|
userPhoneNumber: phoneNumber,
|
|
@@ -2263,7 +2266,8 @@ class TurnkeyClient {
|
|
|
2263
2266
|
if (!accountRes) {
|
|
2264
2267
|
throw new sdkTypes.TurnkeyError(`Account fetch failed`, sdkTypes.TurnkeyErrorCodes.ACCOUNT_FETCH_ERROR);
|
|
2265
2268
|
}
|
|
2266
|
-
if (accountRes.organizationId
|
|
2269
|
+
if (accountRes.organizationId &&
|
|
2270
|
+
accountRes.organizationId !== session?.organizationId) {
|
|
2267
2271
|
throw new sdkTypes.TurnkeyError("Account already exists with this OIDC token", sdkTypes.TurnkeyErrorCodes.ACCOUNT_ALREADY_EXISTS);
|
|
2268
2272
|
}
|
|
2269
2273
|
const userId = params?.userId || session?.userId;
|
|
@@ -2280,18 +2284,33 @@ class TurnkeyClient {
|
|
|
2280
2284
|
const verifiedSuborg = await this.httpClient.proxyGetAccount({
|
|
2281
2285
|
filterType: "EMAIL",
|
|
2282
2286
|
filterValue: oidcEmail,
|
|
2287
|
+
oidcToken: oidcToken,
|
|
2283
2288
|
});
|
|
2284
2289
|
const isVerified = verifiedSuborg.organizationId === organizationId;
|
|
2285
2290
|
const user = await this.fetchUser({
|
|
2286
2291
|
userId,
|
|
2287
2292
|
stampWith,
|
|
2288
2293
|
});
|
|
2294
|
+
// this block's pupose is for social linking, it's important that we update the email BEFORE we call createOauthProviders
|
|
2295
|
+
// since for social linking createOauthProviders will mark the email as verified as long as it's the same one that lives in the
|
|
2296
|
+
// OIDC token.
|
|
2289
2297
|
if (!user?.userEmail && !isVerified) {
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2298
|
+
// we cannot use our sugared updateUserEmail here since we need to pass in the oidcToken in case Require Verification Token On Account Lookup is enabled
|
|
2299
|
+
// in the dashboard
|
|
2300
|
+
const existingUser = await this.httpClient.proxyGetAccount({
|
|
2301
|
+
filterType: enums.FilterType.Email,
|
|
2302
|
+
filterValue: oidcEmail,
|
|
2303
|
+
oidcToken: oidcToken,
|
|
2294
2304
|
});
|
|
2305
|
+
if (existingUser.organizationId) {
|
|
2306
|
+
throw new sdkTypes.TurnkeyError(`Email ${oidcEmail} is already associated with another user.`, sdkTypes.TurnkeyErrorCodes.ACCOUNT_ALREADY_EXISTS);
|
|
2307
|
+
}
|
|
2308
|
+
// update and verify their email since we got it from a verified OIDC token
|
|
2309
|
+
await this.httpClient.updateUserEmail({
|
|
2310
|
+
userId,
|
|
2311
|
+
userEmail: oidcEmail,
|
|
2312
|
+
organizationId,
|
|
2313
|
+
}, stampWith);
|
|
2295
2314
|
}
|
|
2296
2315
|
}
|
|
2297
2316
|
const createProviderRes = await this.httpClient.createOauthProviders({
|
|
@@ -3211,7 +3230,7 @@ class TurnkeyClient {
|
|
|
3211
3230
|
};
|
|
3212
3231
|
this.config = config;
|
|
3213
3232
|
// Just store any explicitly provided stampers
|
|
3214
|
-
this.apiKeyStamper = apiKeyStamper;
|
|
3233
|
+
this.apiKeyStamper = apiKeyStamper$1;
|
|
3215
3234
|
this.passkeyStamper = passkeyStamper;
|
|
3216
3235
|
this.walletManager = walletManager;
|
|
3217
3236
|
// Actual initialization will happen in init()
|