@originals/auth 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,8 @@
1
1
  /**
2
2
  * Server-side Turnkey client utilities
3
- *
4
- * Uses @turnkey/http for lightweight HTTP-only API access (~23MB)
5
- * instead of @turnkey/sdk-server which pulls in heavy EVM dependencies (~125MB+)
6
3
  */
7
4
 
8
- import { TurnkeyClient } from '@turnkey/http';
9
- import { ApiKeyStamper } from '@turnkey/api-key-stamper';
5
+ import { Turnkey } from '@turnkey/sdk-server';
10
6
 
11
7
  export interface TurnkeyClientConfig {
12
8
  /** Turnkey API base URL (default: https://api.turnkey.com) */
@@ -20,174 +16,9 @@ export interface TurnkeyClientConfig {
20
16
  }
21
17
 
22
18
  /**
23
- * Wrapper class that provides the same simplified interface as @turnkey/sdk-server
24
- * but uses the lightweight @turnkey/http package (~23MB vs ~125MB+)
19
+ * Create a Turnkey server client
25
20
  */
26
- export class TurnkeyHttpClient {
27
- private client: TurnkeyClient;
28
- public readonly organizationId: string;
29
-
30
- constructor(client: TurnkeyClient, organizationId: string) {
31
- this.client = client;
32
- this.organizationId = organizationId;
33
- }
34
-
35
- /**
36
- * Get the underlying HTTP client for direct API access
37
- */
38
- apiClient() {
39
- const self = this;
40
- return {
41
- /** Get sub-organization IDs */
42
- async getSubOrgIds(params: {
43
- organizationId: string;
44
- filterType: string;
45
- filterValue: string;
46
- }) {
47
- const result = await self.client.getSubOrgIds({
48
- organizationId: params.organizationId,
49
- filterType: params.filterType,
50
- filterValue: params.filterValue,
51
- });
52
- return result;
53
- },
54
-
55
- /** Get wallets for an organization */
56
- async getWallets(params: { organizationId: string }) {
57
- const result = await self.client.getWallets({
58
- organizationId: params.organizationId,
59
- });
60
- return result;
61
- },
62
-
63
- /** Create a sub-organization with wallet */
64
- async createSubOrganization(params: {
65
- subOrganizationName: string;
66
- rootUsers: Array<{
67
- userName: string;
68
- userEmail: string;
69
- apiKeys: unknown[];
70
- authenticators: unknown[];
71
- oauthProviders: unknown[];
72
- }>;
73
- rootQuorumThreshold: number;
74
- wallet: {
75
- walletName: string;
76
- accounts: Array<{
77
- curve: string;
78
- pathFormat: string;
79
- path: string;
80
- addressFormat: string;
81
- }>;
82
- };
83
- }) {
84
- const result = await self.client.createSubOrganization({
85
- type: 'ACTIVITY_TYPE_CREATE_SUB_ORGANIZATION_V7',
86
- timestampMs: Date.now().toString(),
87
- organizationId: self.organizationId,
88
- parameters: {
89
- subOrganizationName: params.subOrganizationName,
90
- rootUsers: params.rootUsers.map(user => ({
91
- userName: user.userName,
92
- userEmail: user.userEmail,
93
- apiKeys: user.apiKeys as [],
94
- authenticators: user.authenticators as [],
95
- oauthProviders: user.oauthProviders as [],
96
- })),
97
- rootQuorumThreshold: params.rootQuorumThreshold,
98
- wallet: {
99
- walletName: params.wallet.walletName,
100
- accounts: params.wallet.accounts.map(acc => ({
101
- curve: acc.curve as 'CURVE_SECP256K1' | 'CURVE_ED25519',
102
- pathFormat: acc.pathFormat as 'PATH_FORMAT_BIP32',
103
- path: acc.path,
104
- addressFormat: acc.addressFormat as 'ADDRESS_FORMAT_ETHEREUM' | 'ADDRESS_FORMAT_SOLANA',
105
- })),
106
- },
107
- },
108
- });
109
- return result;
110
- },
111
-
112
- /** Initialize OTP */
113
- async initOtp(params: {
114
- otpType: string;
115
- contact: string;
116
- userIdentifier: string;
117
- appName: string;
118
- otpLength: number;
119
- alphanumeric: boolean;
120
- }) {
121
- const result = await self.client.initOtp({
122
- type: 'ACTIVITY_TYPE_INIT_OTP_V2',
123
- timestampMs: Date.now().toString(),
124
- organizationId: self.organizationId,
125
- parameters: {
126
- otpType: params.otpType as 'OTP_TYPE_EMAIL' | 'OTP_TYPE_SMS',
127
- contact: params.contact,
128
- userIdentifier: params.userIdentifier,
129
- appName: params.appName,
130
- otpLength: params.otpLength,
131
- alphanumeric: params.alphanumeric,
132
- },
133
- });
134
- // Extract otpId from the activity result
135
- const activity = result.activity;
136
- const initResult = (activity?.result as { initOtpResult?: { otpId?: string } })?.initOtpResult;
137
- return { otpId: initResult?.otpId };
138
- },
139
-
140
- /** Verify OTP */
141
- async verifyOtp(params: {
142
- otpId: string;
143
- otpCode: string;
144
- expirationSeconds: string;
145
- }) {
146
- const result = await self.client.verifyOtp({
147
- type: 'ACTIVITY_TYPE_VERIFY_OTP',
148
- timestampMs: Date.now().toString(),
149
- organizationId: self.organizationId,
150
- parameters: {
151
- otpId: params.otpId,
152
- otpCode: params.otpCode,
153
- expirationSeconds: params.expirationSeconds,
154
- },
155
- });
156
- // Extract verification token from activity result
157
- const activity = result.activity;
158
- const verifyResult = (activity?.result as { verifyOtpResult?: { verificationToken?: string } })?.verifyOtpResult;
159
- return { verificationToken: verifyResult?.verificationToken };
160
- },
161
-
162
- /** Sign raw payload */
163
- async signRawPayload(params: {
164
- organizationId: string;
165
- signWith: string;
166
- payload: string;
167
- encoding: string;
168
- hashFunction: string;
169
- }) {
170
- const result = await self.client.signRawPayload({
171
- type: 'ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2',
172
- timestampMs: Date.now().toString(),
173
- organizationId: params.organizationId,
174
- parameters: {
175
- signWith: params.signWith,
176
- payload: params.payload,
177
- encoding: params.encoding as 'PAYLOAD_ENCODING_HEXADECIMAL',
178
- hashFunction: params.hashFunction as 'HASH_FUNCTION_NO_OP',
179
- },
180
- });
181
- return result;
182
- },
183
- };
184
- }
185
- }
186
-
187
- /**
188
- * Create a Turnkey server client using the lightweight HTTP package
189
- */
190
- export function createTurnkeyClient(config?: Partial<TurnkeyClientConfig>): TurnkeyHttpClient {
21
+ export function createTurnkeyClient(config?: Partial<TurnkeyClientConfig>): Turnkey {
191
22
  const apiPublicKey = config?.apiPublicKey ?? process.env.TURNKEY_API_PUBLIC_KEY;
192
23
  const apiPrivateKey = config?.apiPrivateKey ?? process.env.TURNKEY_API_PRIVATE_KEY;
193
24
  const organizationId = config?.organizationId ?? process.env.TURNKEY_ORGANIZATION_ID;
@@ -202,19 +33,12 @@ export function createTurnkeyClient(config?: Partial<TurnkeyClientConfig>): Turn
202
33
  throw new Error('TURNKEY_ORGANIZATION_ID is required');
203
34
  }
204
35
 
205
- // Create API key stamper for request signing
206
- const stamper = new ApiKeyStamper({
36
+ return new Turnkey({
37
+ apiBaseUrl: config?.apiBaseUrl ?? 'https://api.turnkey.com',
207
38
  apiPublicKey,
208
39
  apiPrivateKey,
40
+ defaultOrganizationId: organizationId,
209
41
  });
210
-
211
- // Create HTTP client
212
- const client = new TurnkeyClient(
213
- { baseUrl: config?.apiBaseUrl ?? 'https://api.turnkey.com' },
214
- stamper
215
- );
216
-
217
- return new TurnkeyHttpClient(client, organizationId);
218
42
  }
219
43
 
220
44
  /**
@@ -223,7 +47,7 @@ export function createTurnkeyClient(config?: Partial<TurnkeyClientConfig>): Turn
223
47
  */
224
48
  export async function getOrCreateTurnkeySubOrg(
225
49
  email: string,
226
- turnkeyClient: TurnkeyHttpClient
50
+ turnkeyClient: Turnkey
227
51
  ): Promise<string> {
228
52
  const organizationId = process.env.TURNKEY_ORGANIZATION_ID;
229
53
  if (!organizationId) {
@@ -5,11 +5,11 @@
5
5
  * keys for use with the Originals SDK's DID creation and signing operations.
6
6
  */
7
7
 
8
+ import { Turnkey } from '@turnkey/sdk-server';
8
9
  import { ExternalSigner, ExternalVerifier, multikey, OriginalsSDK } from '@originals/sdk';
9
10
  import { sha512 } from '@noble/hashes/sha2.js';
10
11
  import { concatBytes, bytesToHex } from '@noble/hashes/utils.js';
11
12
  import * as ed25519 from '@noble/ed25519';
12
- import type { TurnkeyHttpClient } from './turnkey-client';
13
13
 
14
14
  // Configure @noble/ed25519 with required SHA-512 function
15
15
  const sha512Fn = (...msgs: Uint8Array[]): Uint8Array => sha512(concatBytes(...msgs));
@@ -38,14 +38,14 @@ export class TurnkeyWebVHSigner implements ExternalSigner, ExternalVerifier {
38
38
  private subOrgId: string;
39
39
  private keyId: string;
40
40
  private publicKeyMultibase: string;
41
- private turnkeyClient: TurnkeyHttpClient;
41
+ private turnkeyClient: Turnkey;
42
42
  private verificationMethodId: string;
43
43
 
44
44
  constructor(
45
45
  subOrgId: string,
46
46
  keyId: string,
47
47
  publicKeyMultibase: string,
48
- turnkeyClient: TurnkeyHttpClient,
48
+ turnkeyClient: Turnkey,
49
49
  verificationMethodId: string
50
50
  ) {
51
51
  this.subOrgId = subOrgId;
@@ -155,7 +155,7 @@ export class TurnkeyWebVHSigner implements ExternalSigner, ExternalVerifier {
155
155
  export function createTurnkeySigner(
156
156
  subOrgId: string,
157
157
  keyId: string,
158
- turnkeyClient: TurnkeyHttpClient,
158
+ turnkeyClient: Turnkey,
159
159
  verificationMethodId: string,
160
160
  publicKeyMultibase: string
161
161
  ): TurnkeyWebVHSigner {