Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
c243cd1
feat: import tss key + recover Tss Key
ieow Sep 27, 2023
55650dd
feat: add tests
ieow Sep 28, 2023
80b1b38
Merge branch 'feat/recoverTssKey+importTssKey' into feat/add-tests
ieow Sep 29, 2023
92f037a
fix: add test for importTssKey
ieow Oct 2, 2023
e382afc
feat: update tkey package
ieow Oct 3, 2023
ae1466d
fix: cleanup
ieow Oct 3, 2023
bec85a9
fix: add resetaccount to tests
ieow Oct 3, 2023
34894c1
Merge branch 'alpha' into feat/recoverTssKey+importTssKey
ieow Oct 3, 2023
e7d7e20
Merge branch 'master' into feat/recoverTssKey+importTssKey
ieow Oct 4, 2023
ad12001
fix: add unsafe prefix
ieow Oct 4, 2023
bbc81bb
Merge branch 'alpha' into feat/recoverTssKey+importTssKey
ieow Oct 10, 2023
468fa21
fix: update mockLogin
ieow Oct 11, 2023
ffb7887
fix: token generation
ieow Oct 11, 2023
bde9f43
fix: jsonwebtoken package
ieow Oct 11, 2023
ce21110
feat: enable tests
ieow Oct 11, 2023
eb68747
fix: tests
ieow Oct 12, 2023
1e695ed
Merge branch 'master' into feat/enable-tests
ieow Oct 13, 2023
46bc250
Merge branch 'master' into feat/enable-tests
ieow Oct 13, 2023
da43d26
update: enable nodejs
ieow Oct 20, 2023
5561ccc
fix: revert to private for BrowserStorage
ieow Oct 20, 2023
9e47618
feat: enable signing nodejs
ieow Oct 24, 2023
8fba501
feat: make public sign and getPublic function
ieow Oct 24, 2023
766a99d
fix: add checking for nodejs with tssLib
ieow Oct 24, 2023
6d101c4
fix: enable back tests
ieow Oct 26, 2023
fd6e97a
fix: remove unused pacakges
ieow Oct 26, 2023
32208be
fix: add signing test
ieow Oct 26, 2023
7116c7a
feat: enable server side mpc-core-kit signing
ieow Oct 27, 2023
8643554
feat: remote sign refresh
ieow Oct 30, 2023
5c86cb8
feat: integrate remoteSign to mpcCorekit
ieow Nov 1, 2023
718e3f9
stable: sms authentication integrated
ieow Nov 2, 2023
e1dd2e8
fix: authenticator remote setup
ieow Nov 2, 2023
cf48efb
fix: use authorization header for token
ieow Nov 2, 2023
266146e
chore: cleanup
ieow Nov 2, 2023
f6845f3
fix: rehydration
ieow Nov 7, 2023
0ac55a4
feat: authorization signing
ieow Nov 7, 2023
5ce6c1d
fix: correct api input
ieow Nov 7, 2023
a733144
fix: add disable option
ieow Nov 7, 2023
ff3dd9c
update: interface
ieow Nov 7, 2023
013ae2d
fix: typo
ieow Nov 7, 2023
8c895fa
fix: catch on fail precompute - client.ready
ieow Nov 9, 2023
2f11057
fix: update tss-client to 2.0.0
ieow Nov 9, 2023
7d64456
chore: cleanup
ieow Nov 9, 2023
ecf04a3
fix: sync nodeIndexes with endpoints
ieow Nov 10, 2023
7a24170
refactor: update api path
ieow Nov 16, 2023
416aa13
fix: update remote api to v3
ieow Nov 16, 2023
3b507a2
fix: wasm endpoint path
ieow Nov 16, 2023
08ea3b3
fix: package-lock.json
ieow Nov 22, 2023
3457595
fix: use latest metadata-helper
ieow Nov 23, 2023
cde6c21
fix: move importTssKey to params arg
ieow Nov 23, 2023
bbe11fc
Merge branch 'master' into feat/authorization-signing
ieow Dec 6, 2023
c625c06
fix: merge issue
ieow Dec 6, 2023
96f353d
feat: nodeIndex always available
ieow Dec 7, 2023
f620f85
fix: address comment on recoveryTssKey
ieow Dec 7, 2023
f033702
merge with master
Apr 17, 2024
ee51182
lock fixed
Apr 17, 2024
092cdd0
merge with v3
Apr 17, 2024
8f8aecd
get signing signatures fixed
Apr 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 34 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@toruslabs/constants": "^13.0.1",
"@toruslabs/customauth": "^18.1.0",
"@toruslabs/eccrypto": "4.0.0",
"@toruslabs/http-helpers": "^5.0.0",
"@toruslabs/fetch-node-details": "^13.1.1",
"@toruslabs/fnd-base": "^13.1.1",
"@toruslabs/metadata-helpers": "^5.x",
Expand All @@ -57,7 +58,8 @@
"@web3auth/base-provider": "^7.3.1",
"bn.js": "^5.2.1",
"bowser": "^2.11.0",
"elliptic": "^6.5.4"
"elliptic": "^6.5.4",
"hi-base32": "^0.5.1"
},
"devDependencies": {
"@babel/register": "^7.23.7",
Expand Down
6 changes: 6 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ export const CURVE = new EllipticCurve("secp256k1");

export const MAX_FACTORS = 10; // Maximum number of factors that can be added to an account.
export const SOCIAL_TKEY_INDEX = 1;

export const OPS = {
DELETE_FACTOR: "delete_factor",
CREATE_FACTOR: "created_factor",
LOCAL_SIGN: "local_sign",
};
128 changes: 128 additions & 0 deletions src/helper/authenticator/authenticatorService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { generatePrivate } from "@toruslabs/eccrypto";
import { post } from "@toruslabs/http-helpers";
import { keccak256 } from "@toruslabs/metadata-helpers";
import { log } from "@web3auth/base";
import BN from "bn.js";
import type { ec } from "elliptic";
import base32 from "hi-base32";

import { CURVE } from "../../constants";
import { IRemoteClientState, Web3AuthMPCCoreKit } from "../../index";

export class AuthenticatorService {
private backendUrl: string;

private coreKitInstance: Web3AuthMPCCoreKit;

private authenticatorType: string = "authenticator";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the type of authenticatorType variable based on accepted values


private factorPub: string = "";

private tssIndex: number;

constructor(params: { backendUrl: string; coreKitInstance: Web3AuthMPCCoreKit; authenticatorType?: string }) {
const { backendUrl } = params;
this.backendUrl = backendUrl;
this.authenticatorType = params.authenticatorType || "authenticator";
this.coreKitInstance = params.coreKitInstance;
// this.remoteClient = remoteClient || false;
}

getDescriptionsAndUpdate() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specify return type

const arrayOfDescriptions = Object.entries(this.coreKitInstance.getKeyDetails().shareDescriptions).map(([key, value]) => {
const parsedDescription = (value || [])[0] ? JSON.parse(value[0]) : {};
return {
key,
description: parsedDescription,
};
});

const shareDescriptionsMobile = arrayOfDescriptions.find(({ description }) => description.authenticator === this.authenticatorType);
log.info("shareDescriptionsMobile", shareDescriptionsMobile);

if (shareDescriptionsMobile) {
this.factorPub = shareDescriptionsMobile.key;
this.tssIndex = shareDescriptionsMobile.description.tssShareIndex;
}

return shareDescriptionsMobile;
}

generateSecretKey(): string {
const key = generatePrivate().subarray(0, 20);
return base32.encode(key).toString().replace(/=/g, "");
}

async register(privKey: BN, secretKey: string): Promise<{ success: boolean; message?: string }> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whts the diff b/w private key and secret key? is their any example or flow diagram where i can see usage of this class

const privKeyPair: ec.KeyPair = CURVE.keyFromPrivate(privKey.toString(16, 64));
const pubKey = privKeyPair.getPublic();
const sig = CURVE.sign(keccak256(Buffer.from(secretKey, "utf8")), Buffer.from(privKey.toString(16, 64), "hex"));

const data = {
pubKey: {
x: pubKey.getX().toString(16, 64),
y: pubKey.getY().toString(16, 64),
},
sig: {
r: sig.r.toString(16, 64),
s: sig.s.toString(16, 64),
v: new BN(sig.recoveryParam as number).toString(16, 2),
},
secretKey,
};

const resp = await post<{
success: boolean;
message: string;
}>(`${this.backendUrl}/api/v3/register`, data);

return resp;
}

async addRecovery(address: string, code: string, factorKey: BN) {
if (!factorKey) throw new Error("factorKey is not defined");
if (!address) throw new Error("address is not defined");
if (!code) throw new Error("code is not defined");

const data = {
address,
code,
data: {
// If the verification is complete, we save the factorKey for the user address.
// This factorKey is used to verify the user in the future on a new device and recover tss share.
factorKey: factorKey.toString(16, 64),
},
};

await post(`${this.backendUrl}/api/v3/verify`, data);
}

async verifyRecovery(address: string, code: string): Promise<BN | undefined> {
const verificationData = {
address,
code,
};

const response = await post<{ data?: Record<string, string> }>(`${this.backendUrl}/api/v3/verify`, verificationData);
const { data } = response;
return data ? new BN(data.factorKey, "hex") : undefined;
}

async verifyRemoteSetup(address: string, code: string): Promise<IRemoteClientState & { tssShareIndex: string }> {
const verificationData = {
address,
code,
};

const response = await post<{ data?: Record<string, string> }>(`${this.backendUrl}/api/v3/verify_remote`, verificationData);
const { data } = response;

return {
tssShareIndex: this.tssIndex.toString(),
remoteClientUrl: this.backendUrl,
remoteFactorPub: this.factorPub,
metadataShare: data.metadataShare,
remoteClientToken: data.signature,
};
}
}
Loading