Skip to content

Commit c4e10b3

Browse files
rename types
1 parent d1a910a commit c4e10b3

File tree

9 files changed

+313
-330
lines changed

9 files changed

+313
-330
lines changed

src/helpers/nodeUtils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import {
1616
KeyLookupResult,
1717
LegacyKeyLookupResult,
1818
LegacyVerifierLookupResponse,
19-
RetrieveSharesResponse,
2019
SessionToken,
2120
ShareRequestResult,
2221
SignerResponse,
22+
TorusKey,
2323
UserType,
2424
v2NonceResultType,
2525
VerifierLookupResponse,
@@ -120,7 +120,7 @@ export async function retrieveOrImportShare(params: {
120120
idToken: string;
121121
importedShares?: ImportedShare[];
122122
extraParams: Record<string, unknown>;
123-
}): Promise<RetrieveSharesResponse> {
123+
}): Promise<TorusKey> {
124124
const {
125125
legacyMetadataHost,
126126
serverTimeOffset,
@@ -495,7 +495,7 @@ export async function retrieveOrImportShare(params: {
495495
const oAuthPubkeyY = oAuthPubKey.slice(66);
496496
let metadataNonce = new BN(nonceResult?.nonce ? nonceResult.nonce.padStart(64, "0") : "0", "hex");
497497
let finalPubKey: curve.base.BasePoint;
498-
let pubNonce: { x: string; y: string } | undefined;
498+
let pubNonce: { X: string; Y: string } | undefined;
499499
let typeOfUser: UserType = "v1";
500500
// extended_verifier_id is only exception for torus-test-health verifier
501501
// otherwise extended verifier id should not even return shares.
@@ -507,7 +507,7 @@ export async function retrieveOrImportShare(params: {
507507
if (enableOneKey) {
508508
nonceResult = await getNonce(legacyMetadataHost, ecCurve, serverTimeOffset, oAuthPubkeyX, oAuthPubkeyY, oAuthKey);
509509
metadataNonce = new BN(nonceResult.nonce || "0", 16);
510-
pubNonce = (nonceResult as v2NonceResultType).pubNonce;
510+
pubNonce = { X: (nonceResult as v2NonceResultType).pubNonce.x, Y: (nonceResult as v2NonceResultType).pubNonce.y };
511511
typeOfUser = nonceResult.typeOfUser;
512512
if (typeOfUser === "v2") {
513513
finalPubKey = ecCurve
@@ -534,7 +534,7 @@ export async function retrieveOrImportShare(params: {
534534
.add(
535535
ecCurve.keyFromPublic({ x: (nonceResult as v2NonceResultType).pubNonce.x, y: (nonceResult as v2NonceResultType).pubNonce.y }).getPublic()
536536
);
537-
pubNonce = (nonceResult as v2NonceResultType).pubNonce;
537+
pubNonce = { X: (nonceResult as v2NonceResultType).pubNonce.x, Y: (nonceResult as v2NonceResultType).pubNonce.y };
538538
}
539539

540540
const oAuthKeyAddress = generateAddressFromPrivKey(ecCurve, oAuthKey);
@@ -582,7 +582,7 @@ export async function retrieveOrImportShare(params: {
582582
nodesData: {
583583
nodeIndexes: nodeIndexes.map((x) => x.toNumber()),
584584
},
585-
} as RetrieveSharesResponse;
585+
} as TorusKey;
586586
});
587587
}
588588

src/interfaces.ts

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,6 @@ export interface TorusCtorOptions {
3737
legacyMetadataHost?: string;
3838
}
3939

40-
export interface TorusPublicKey {
41-
oAuthPubKeyData: {
42-
evmAddress: string;
43-
x: string;
44-
y: string;
45-
};
46-
finalPubKeyData: {
47-
evmAddress: string;
48-
x: string;
49-
y: string;
50-
};
51-
metadata: {
52-
pubNonce?: { x: string; y: string };
53-
nonce?: BN;
54-
upgraded: boolean;
55-
typeOfUser: UserType;
56-
};
57-
nodesData: {
58-
nodeIndexes: number[];
59-
};
60-
}
61-
6240
export interface LegacyVerifierLookupResponse {
6341
keys: { pub_key_X: string; pub_key_Y: string; address: string }[];
6442
}
@@ -188,30 +166,20 @@ export interface SessionToken {
188166
node_pubx: string;
189167
node_puby: string;
190168
}
191-
192-
export interface RetrieveSharesResponse {
169+
export interface TorusPublicKey {
193170
finalKeyData: {
194171
evmAddress: string;
195172
X: string; // this is final pub x user before and after updating to 2/n
196173
Y: string; // this is final pub y user before and after updating to 2/n
197-
privKey?: string;
198174
};
199175
oAuthKeyData: {
200176
evmAddress: string;
201177
X: string;
202178
Y: string;
203-
privKey: string;
204-
};
205-
sessionData: {
206-
sessionTokenData: SessionToken[];
207-
sessionAuthKey: string;
208179
};
209180
metadata: {
210-
pubNonce?: {
211-
x: string;
212-
y: string;
213-
};
214-
nonce: BN;
181+
pubNonce?: { X: string; Y: string };
182+
nonce?: BN;
215183
typeOfUser: UserType;
216184
upgraded: boolean | null;
217185
};
@@ -220,6 +188,21 @@ export interface RetrieveSharesResponse {
220188
};
221189
}
222190

191+
export interface TorusKey {
192+
finalKeyData: TorusPublicKey["finalKeyData"] & {
193+
privKey?: string;
194+
};
195+
oAuthKeyData: TorusPublicKey["oAuthKeyData"] & {
196+
privKey: string;
197+
};
198+
sessionData: {
199+
sessionTokenData: SessionToken[];
200+
sessionAuthKey: string;
201+
};
202+
metadata: TorusPublicKey["metadata"] & Required<Pick<TorusPublicKey["metadata"], "nonce">>;
203+
nodesData: TorusPublicKey["nodesData"];
204+
}
205+
223206
export interface VerifierParams {
224207
[key: string]: unknown;
225208
verifier_id: string;

src/torus.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ import {
3333
LegacyShareRequestResult,
3434
LegacyVerifierLookupResponse,
3535
NonceMetadataParams,
36-
RetrieveSharesResponse,
3736
SetNonceData,
3837
TorusCtorOptions,
38+
TorusKey,
3939
TorusPublicKey,
4040
UserType,
4141
v2NonceResultType,
@@ -115,7 +115,7 @@ class Torus {
115115
verifierParams: VerifierParams,
116116
idToken: string,
117117
extraParams: Record<string, unknown> = {}
118-
): Promise<RetrieveSharesResponse> {
118+
): Promise<TorusKey> {
119119
if (this.isLegacyNetwork) return this.legacyRetrieveShares(endpoints, indexes, verifier, verifierParams, idToken, extraParams);
120120
return retrieveOrImportShare({
121121
legacyMetadataHost: this.legacyMetadataHost,
@@ -152,7 +152,7 @@ class Torus {
152152
idToken: string,
153153
newPrivateKey: string,
154154
extraParams: Record<string, unknown> = {}
155-
): Promise<RetrieveSharesResponse> {
155+
): Promise<TorusKey> {
156156
if (this.isLegacyNetwork) throw new Error("This function is not supported on legacy networks");
157157
if (endpoints.length !== nodeIndexes.length) {
158158
throw new Error(`length of endpoints array must be same as length of nodeIndexes array`);
@@ -240,7 +240,7 @@ class Torus {
240240
verifierParams: VerifierParams,
241241
idToken: string,
242242
extraParams: Record<string, unknown> = {}
243-
): Promise<RetrieveSharesResponse> {
243+
): Promise<TorusKey> {
244244
const promiseArr = [];
245245
await get<void>(
246246
this.allowHost,
@@ -442,7 +442,7 @@ class Torus {
442442
let metadataNonce: BN;
443443
let finalPubKey: curve.base.BasePoint;
444444
let typeOfUser: UserType = "v1";
445-
let pubKeyNonceResult: { x: string; y: string } | undefined;
445+
let pubKeyNonceResult: { X: string; Y: string } | undefined;
446446
if (this.enableOneKey) {
447447
const nonceResult = await getNonce(this.legacyMetadataHost, this.ec, this.serverTimeOffset, oAuthKeyX, oAuthKeyY, oAuthKey);
448448
metadataNonce = new BN(nonceResult.nonce || "0", 16);
@@ -456,7 +456,7 @@ class Torus {
456456
.keyFromPublic({ x: (nonceResult as v2NonceResultType).pubNonce.x, y: (nonceResult as v2NonceResultType).pubNonce.y })
457457
.getPublic()
458458
);
459-
pubKeyNonceResult = (nonceResult as v2NonceResultType).pubNonce;
459+
pubKeyNonceResult = { X: (nonceResult as v2NonceResultType).pubNonce.x, Y: (nonceResult as v2NonceResultType).pubNonce.y };
460460
}
461461
} else {
462462
// for imported keys in legacy networks
@@ -615,7 +615,7 @@ class Torus {
615615
throw new GetOrSetNonceError("metadata nonce is missing in share response");
616616
}
617617
const { pub_key_X: X, pub_key_Y: Y } = keyResult.keys[0];
618-
let pubNonce: { x: string; y: string } | undefined;
618+
let pubNonce: { X: string; Y: string } | undefined;
619619
const nonce = new BN(nonceResult?.nonce || "0", 16);
620620
let oAuthPubKey: curve.base.BasePoint;
621621
let finalPubKey: curve.base.BasePoint;
@@ -639,7 +639,7 @@ class Torus {
639639
.getPublic()
640640
.add(this.ec.keyFromPublic({ x: v2NonceResult.pubNonce.x, y: v2NonceResult.pubNonce.y }).getPublic());
641641

642-
pubNonce = v2NonceResult.pubNonce;
642+
pubNonce = { X: v2NonceResult.pubNonce.x, Y: v2NonceResult.pubNonce.y };
643643
}
644644

645645
if (!oAuthPubKey) {
@@ -648,7 +648,7 @@ class Torus {
648648
const oAuthX = oAuthPubKey.getX().toString(16, 64);
649649
const oAuthY = oAuthPubKey.getY().toString(16, 64);
650650
const oAuthAddress = generateAddressFromPubKey(this.ec, oAuthPubKey.getX(), oAuthPubKey.getY());
651-
log.debug("> torus.js/getPublicAddress, oAuthPubKeyData", { X: oAuthX, Y: oAuthY, oAuthAddress, nonce: nonce?.toString(16), pubNonce });
651+
log.debug("> torus.js/getPublicAddress, oAuthKeyData", { X: oAuthX, Y: oAuthY, oAuthAddress, nonce: nonce?.toString(16), pubNonce });
652652

653653
if (!finalPubKey) {
654654
throw new Error("Unable to derive finalPubKey");
@@ -657,15 +657,15 @@ class Torus {
657657
const finalY = finalPubKey ? finalPubKey.getY().toString(16, 64) : "";
658658
const finalAddress = finalPubKey ? generateAddressFromPubKey(this.ec, finalPubKey.getX(), finalPubKey.getY()) : "";
659659
return {
660-
oAuthPubKeyData: {
660+
oAuthKeyData: {
661661
evmAddress: oAuthAddress,
662-
x: oAuthX,
663-
y: oAuthY,
662+
X: oAuthX,
663+
Y: oAuthY,
664664
},
665-
finalPubKeyData: {
665+
finalKeyData: {
666666
evmAddress: finalAddress,
667-
x: finalX,
668-
y: finalY,
667+
X: finalX,
668+
Y: finalY,
669669
},
670670
metadata: {
671671
pubNonce,
@@ -690,7 +690,7 @@ class Torus {
690690
let nonce: BN;
691691
let finalPubKey: curve.base.BasePoint;
692692
let typeOfUser: GetOrSetNonceResult["typeOfUser"];
693-
let pubNonce: { x: string; y: string } | undefined;
693+
let pubNonce: { X: string; Y: string } | undefined;
694694

695695
const oAuthPubKey = this.ec.keyFromPublic({ x: X, y: Y }).getPublic();
696696

@@ -712,7 +712,7 @@ class Torus {
712712
.keyFromPublic({ x: X, y: Y })
713713
.getPublic()
714714
.add(this.ec.keyFromPublic({ x: nonceResult.pubNonce.x, y: nonceResult.pubNonce.y }).getPublic());
715-
pubNonce = nonceResult.pubNonce;
715+
pubNonce = { X: nonceResult.pubNonce.x, Y: nonceResult.pubNonce.y };
716716
} else {
717717
throw new Error("getOrSetNonce should always return typeOfUser.");
718718
}
@@ -731,7 +731,7 @@ class Torus {
731731
const oAuthX = oAuthPubKey.getX().toString(16, 64);
732732
const oAuthY = oAuthPubKey.getY().toString(16, 64);
733733
const oAuthAddress = generateAddressFromPubKey(this.ec, oAuthPubKey.getX(), oAuthPubKey.getY());
734-
log.debug("> torus.js/getPublicAddress, oAuthPubKeyData", { X: oAuthX, Y: oAuthY, oAuthAddress, nonce: nonce?.toString(16), pubNonce });
734+
log.debug("> torus.js/getPublicAddress, oAuthKeyData", { X: oAuthX, Y: oAuthY, oAuthAddress, nonce: nonce?.toString(16), pubNonce });
735735

736736
if (typeOfUser === "v2" && !finalPubKey) {
737737
throw new Error("Unable to derive finalPubKey");
@@ -740,15 +740,15 @@ class Torus {
740740
const finalY = finalPubKey ? finalPubKey.getY().toString(16, 64) : "";
741741
const finalAddress = finalPubKey ? generateAddressFromPubKey(this.ec, finalPubKey.getX(), finalPubKey.getY()) : "";
742742
return {
743-
oAuthPubKeyData: {
743+
oAuthKeyData: {
744744
evmAddress: oAuthAddress,
745-
x: oAuthX,
746-
y: oAuthY,
745+
X: oAuthX,
746+
Y: oAuthY,
747747
},
748-
finalPubKeyData: {
748+
finalKeyData: {
749749
evmAddress: finalAddress,
750-
x: finalX,
751-
y: finalY,
750+
X: finalX,
751+
Y: finalY,
752752
},
753753
metadata: {
754754
pubNonce,

0 commit comments

Comments
 (0)