Skip to content

Commit

Permalink
return postbox key data obj
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu committed May 9, 2024
1 parent 9cca752 commit 49094e4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 76 deletions.
10 changes: 0 additions & 10 deletions src/helpers/keyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ export const getSecpKeyFromEd25519 = (
const secpKeyPair = secp256k1Curve.keyFromPrivate(bufferKey);

if (bufferKey.length < 32) {
console.log(
"secpKey.toArrayLike(Buffer)",
ed25519Key,
secpKey,
keyHash.length,
bufferKey.length,
secpKeyPair.getPrivate().toArrayLike(Buffer).length
);
throw new Error("Invalid key length, please try again");
}
return {
Expand Down Expand Up @@ -132,8 +124,6 @@ export const generateEd25519KeyData = async (ed25519Seed: Buffer): Promise<Priva
const oauthKey = finalEd25519Key.scalar.sub(metadataPrivNonce).umod(ed25519Curve.n);
const oauthKeyPair = ed25519Curve.keyFromPrivate(oauthKey.toArrayLike(Buffer));
const metadataSigningKey = getSecpKeyFromEd25519(oauthKeyPair.getPrivate());
console.log("metadataSigningKey key data", metadataSigningKey.scalar.toString("hex", 64));
console.log("final encryption key", encryptionKey.scalar.toString("hex", 64));
return {
oAuthKeyScalar: oauthKeyPair.getPrivate(),
oAuthPubX: oauthKeyPair.getPublic().getX(),
Expand Down
3 changes: 0 additions & 3 deletions src/helpers/metadataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,13 @@ export const decryptSeedData = async (seedBase64: string, finalUserKey: BN) => {
const decryptionKey = getSecpKeyFromEd25519(finalUserKey);
const seedUtf8 = Buffer.from(seedBase64, "base64").toString("utf-8");
const seedJson = JSON.parse(seedUtf8) as EncryptedSeed;
console.log("final decryption key", decryptionKey.scalar.toString("hex", 64));
const bufferMetadata = {
ephemPublicKey: Buffer.from(seedJson.metadata.ephemPublicKey, "hex"),
iv: Buffer.from(seedJson.metadata.iv, "hex"),
mac: Buffer.from(seedJson.metadata.mac, "hex"),
mode: "AES256",
};
const bufferKey = Buffer.from(decryptionKey.scalar.toString("hex", 64), "hex");
console.log("key len", bufferKey.length);

const decText = await decrypt(bufferKey, {
...bufferMetadata,
ciphertext: Buffer.from(seedJson.enc_text, "hex"),
Expand Down
9 changes: 0 additions & 9 deletions src/helpers/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,6 @@ export async function retrieveOrImportShare(params: {
if (typeOfUser === "v1" || (typeOfUser === "v2" && metadataNonce.gt(new BN(0)))) {
const privateKeyWithNonce = oAuthKey.add(metadataNonce).umod(ecCurve.curve.n);
keyWithNonce = privateKeyWithNonce.toString("hex", 64);
console.log("keyWithNonce", keyWithNonce);
}
if (keyType === "secp256k1") {
finalPrivKey = keyWithNonce;
Expand All @@ -761,14 +760,6 @@ export async function retrieveOrImportShare(params: {
postboxPubX = point.getX().toString(16, 64);
postboxPubY = point.getY().toString(16, 64);
if (thresholdPubKey.SignerX.padStart(64, "0") !== postboxPubX || thresholdPubKey.SignerY.padStart(64, "0") !== postboxPubY) {
console.log(
"thresholdPubKey.SignerX",
thresholdPubKey.SignerX,
postboxPubX,
thresholdPubKey.SignerY,
postboxPubY,
postboxKey.toString("hex", 64)
);
throw new Error("Invalid postbox key");
}
}
Expand Down
108 changes: 54 additions & 54 deletions test/sapphire_devnet_ed25519.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const TORUS_TEST_VERIFIER = "torus-test-health";
const TORUS_TEST_AGGREGATE_VERIFIER = "torus-test-health-aggregate";
const HashEnabledVerifier = "torus-test-verifierid-hash";

describe.only("torus utils ed25519 sapphire devnet", function () {
describe("torus utils ed25519 sapphire devnet", function () {
let torus: TorusUtils;
let TORUS_NODE_MANAGER: NodeManager;

Expand Down Expand Up @@ -107,63 +107,58 @@ describe.only("torus utils ed25519 sapphire devnet", function () {
expect(result2.finalKeyData.walletAddress).eql("3TTBP4g4UZNH1Tga1D4D6tBGrXUpVXcWt1PX2W19CRqM");
});

it.only("should be able to login", async function () {
const testEmail = "[email protected]";
// const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: testEmail };

it("should be able to login", async function () {
const testEmail = "[email protected]";
const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails({ verifier: TORUS_TEST_VERIFIER, verifierId: testEmail });
// await torus.getPublicAddress(nodeDetails.torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails);

const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints;
// torusNodeEndpoints[0] = "example.com";
// torusNodeEndpoints[1] = "example.com";

for (let i = 0; i < 1000; i++) {
const testEmail1 = `[email protected]${i}`;
const token = generateIdToken(`${testEmail1}`, "ES256");
console.log("testEmail1", testEmail1);
const result = await torus.retrieveShares(
torusNodeEndpoints,
nodeDetails.torusIndexes,
TORUS_TEST_VERIFIER,
{ verifier_id: testEmail1 },
token,
nodeDetails.torusNodePub
);
console.log("result", result.finalKeyData.privKey);
}

// delete result.metadata.serverTimeOffset;
// delete result.sessionData;
// expect(result).eql({
// oAuthKeyData: {
// walletAddress: "7yZNbrFdLgE1ck8BQvDfNpVsgU5BYXotEoXiasTwdWWr",
// X: "7a5d7618aa6abff0a27fd273cd38ef2f81c19a67c488f65d2587b2d7a744dd70",
// Y: "179de2aa479958f2a744b6a8810a38e27257679d09f183f9aa5b2ff81f40a367",
// privKey: "0325b66f131f040fbd23f8feb9633f10440986c5413063f6dd3f23166503b5ea",
// },
// finalKeyData: {
// walletAddress: "7iBcf5du7C7pCocbvoXHDbNXnzF9hSTNRuRiqfGC56Th",
// X: "738dfd57d80945defc6d3bc4deeeffbcecf344a4186b1e756eae54c5f60a4b63",
// Y: "7082c093c550e1069935a6f7f639901c84e14e4030a8561cba4b8ccfd7efb263",
// privKey: "082d9495b9147bac19699ae3109606cbaeea1bf65772b6d7e652ebf77f67f783",
// },
// metadata: {
// pubNonce: {
// X: "4533a0c1907b12187ab41bceaefee8d62b2709d66b67b51a6f39925bfb543933",
// Y: "6862380e59f04a6bbdb3515ee386af44961b403cc61c7cb9725d2e60d250b82",
// },
// nonce: new BN("da32347189e4a992a9367cb8970d741fff3febccd9d92bb5ac247d97dc5c510", "hex"),
// typeOfUser: "v2",
// upgraded: false,
// },
// nodesData: result.nodesData,
// });
// const result2 = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, {
// verifier: TORUS_TEST_VERIFIER,
// verifierId: testEmail,
// });
// expect(result2.finalKeyData.walletAddress).eql(result.finalKeyData.walletAddress);
const token = generateIdToken(`${testEmail}`, "ES256");
const result = await torus.retrieveShares(
torusNodeEndpoints,
nodeDetails.torusIndexes,
TORUS_TEST_VERIFIER,
{ verifier_id: testEmail },
token,
nodeDetails.torusNodePub
);

delete result.metadata.serverTimeOffset;
delete result.sessionData;
expect(result).eql({
oAuthKeyData: {
walletAddress: "HV19ETHePfCtZK55Bo5znHXLfd46nu4AQbjtbYumY7ea",
X: "1f5f95f5af0a67b4af731608fdb26115efcb011dcf64a355bf2442e4ec058ae0",
Y: "33f3317a574a5444b78aecc56dd894a56d1fbb90134bc7c63d0f9d11f969e7f4",
privKey: "07b1ff9ec97c93ac3d5125db8283ec0b22056623d0a9407a48c9def302db07b7",
},
postboxKeyData: {
X: "a7fa19a07eb387e3b1a95843f7d56f8ca88d11c632c4f53b8554068876451d27",
Y: "6ddc5c79c28d197991ecf9304b4e66ecc2e98dcf3cb73ec3c79953bd87e4a6ff",
privKey: "fa5efb87dbdcea273654342d622fcbfa087f4a572caf76d2214e00a8732c6ddf",
},
finalKeyData: {
walletAddress: "Dp6eiDQs7LbHLVATSEaA7NUm9DkEAZTXdzXy13vbYoq8",
X: "2cfc2713bd866494690b50d0cb1500878903130a0a1a31fae1ffa5f8cd436407",
Y: "775cc21e123af488ad2c1fd70b22f9427a0596691c991186d42e69fa08ee5cbe",
privKey: "cfe3a737880b01da41765e90466400512564bf3e12648e8e715ae54b53b1e11b",
},
metadata: {
pubNonce: {
X: "78f007266e249301a241bcb72dba7d305f41f11a432dd8f4dec22c9a0035b3ac",
Y: "7e0545c176528910726ad528e12e1fa39e106ad06957e807a2660c9214596d33",
},
nonce: new BN("58c39dd2c8dcdbd740b758623c88b9dfb36d6e3b590d073a1456c0268af8270", "hex"),
typeOfUser: "v2",
upgraded: false,
},
nodesData: result.nodesData,
});
const result2 = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, {
verifier: TORUS_TEST_VERIFIER,
verifierId: testEmail,
});
expect(result2.finalKeyData.walletAddress).eql(result.finalKeyData.walletAddress);
});

it("should be able to key assign", async function () {
Expand Down Expand Up @@ -367,6 +362,11 @@ describe.only("torus utils ed25519 sapphire devnet", function () {
Y: "44af643f9200d11c5f60212de9470f92806df18eeea730a8736e4570611761f2",
privKey: "47c471c6c3b53f751e39feae967359b9258a790a30f2db394625f76b0c84ada0",
},
postboxKeyData: {
X: "8a25dd3b35a77927e5f094b333ccd69a77acec89868db646e2afbf363f191b11",
Y: "aa9282b02c5af9d06d206631ac503c218f807f0365c0a8677f6347fd01f8ffb0",
privKey: "239c7b52e39074d8c580e3fcd2950dbd2562e8b54340d2628bac055546b6a97e",
},
oAuthKeyData: {
walletAddress: "DybMLmBwiPqt8GXpDW2MwHi5ZqEtrbgxgwcf7shPdTWg",
X: "45c531429896ab89078789018b21639dab308b7d3952d9df243177e60fc0eb1f",
Expand Down

0 comments on commit 49094e4

Please sign in to comment.