Skip to content

Commit

Permalink
feat: enable ed25519
Browse files Browse the repository at this point in the history
  • Loading branch information
ieow committed Oct 22, 2024
1 parent 90762c3 commit 8394365
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 8 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
"author": "Web3Auth",
"license": "BSD",
"dependencies": {
"@web3auth/mpc-core-kit": "^3.2.4",
"@toruslabs/tss-dkls-lib": "^4.0.0"
"@toruslabs/tss-dkls-lib": "^4.0.0",
"@toruslabs/tss-frost-lib": "^1.0.0",
"@web3auth/mpc-core-kit": "^3.2.4"
},
"devDependencies": {
"@babel/core": "7.22.11",
Expand All @@ -44,21 +45,21 @@
"@toruslabs/torus-scripts": "^5.1.0",
"@types/node": "20.10.1",
"@types/react": "^18.2.42",
"loglevel": "1.9.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-native": "^0.75.2",
"react-native-react-bridge": "^0.12.1",
"react-native-webview": "^13.6.3",
"loglevel": "1.9.2",
"rimraf": "5.0.5",
"rollup": "4.7.0",
"ts-jest": "29.1.1",
"tslib": "2.6.2",
"typescript": "5.0.4"
},
"peerDependencies": {
"loglevel": ">=1.0.0, <2.0.0",
"@toruslabs/eccrypto": ">=5.0.0, <6.0.0",
"loglevel": ">=1.0.0, <2.0.0",
"react-native-react-bridge": ">=0.12.1, <0.13.0",
"react-native-webview": ">=13.6.0, <14.0.0"
}
Expand Down
4 changes: 3 additions & 1 deletion src/WebApp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
webViewCreateRoot,
} from 'react-native-react-bridge/lib/web';
import TssLibv4 from '@toruslabs/tss-dkls-lib';
import TssFrost from '@toruslabs/tss-frost-lib';

import {
type MessageResponse,
Expand Down Expand Up @@ -115,9 +116,10 @@ async function handleResponse(

function createMPCCoreKitInstance(options: Web3AuthOptions, ruid: string) {
debug(options);

const modOptions : Web3AuthOptions = {
...options,
tssLib: TssLibv4,
tssLib: options.tssLib.keyType === TssFrost.keyType ? TssFrost : TssLibv4,
storage: createStorageInstance(ruid),
};

Expand Down
14 changes: 13 additions & 1 deletion src/WebApp/mpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,17 @@ export async function handleMPCCoreKitRequest(
const result = corekitInstance.getKeyDetails();
return { ruid, action, result: { result, status: corekitInstance.status , state: corekitInstance.state} };
}
return { ruid, action, result: 'unknown action' };

if (action === CoreKitAction.getPubKeyPoint) {
const result = corekitInstance.getPubKeyPoint();
return { ruid, action, result: { result, status: corekitInstance.status , state: corekitInstance.state} };
}

if (action === CoreKitAction.getPubKeyEd25519) {
const result = corekitInstance.getPubKeyEd25519();
return { ruid, action, result: { result, status: corekitInstance.status , state: corekitInstance.state} };
}

throw new Error ('unknown action');
// return { ruid, action, result: 'unknown action', error: 'unknown action' };
}
3 changes: 3 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export enum CoreKitAction {
setManualSync = 'set_manual_sync',
setTssWalletIndex = 'set_tss_wallet_index',
getTssFactorPub = 'get_tss_factor_pub',

getPubKeyEd25519 = 'get_pub_key_ed25519',
getPubKeyPoint = 'get_pub_key_point',
}

export enum StorageAction {
Expand Down
13 changes: 12 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
export * from './Bridge';
import * as mpclib from './mpclib';
import { KeyType } from '@tkey/common-types';

export { mpclib };
// using tsslib V3 interface
const TssFrostLib = {
keyType : KeyType.ed25519,
lib: {}
}
const TssDklsLib = {
keyType : KeyType.secp256k1,
lib: {}
}

export { mpclib , TssDklsLib, TssFrostLib };
export default mpclib;
18 changes: 17 additions & 1 deletion src/mpclib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Web3AuthMPCCoreKitRN implements CoreKitSigner {

constructor( options: Web3AuthOptions) {
this.options = options;
this.keyType = options.tssLib.keyType;
this.keyType = options.tssLib.keyType as KeyType;
this._status = COREKIT_STATUS.NOT_INITIALIZED;
this.ruid = undefined;
}
Expand Down Expand Up @@ -190,4 +190,20 @@ export class Web3AuthMPCCoreKitRN implements CoreKitSigner {
public async _UNSAFE_resetAccount(): Promise<void> {
return this.genericRequestWithStateUpdate(CoreKitAction._UNSAFE_resetAccount, {});
}

/**
* Get public key point.
*/
public async getPubKeyPoint(): Promise<Point> {
return this.genericRequestWithStateUpdate(CoreKitAction.getPubKeyPoint, {});
}

/**
* Get public key in ed25519 format.
*
* Throws an error if keytype is not compatible with ed25519.
*/
public async getPubKeyEd25519(): Promise<Buffer> {
return this.genericRequestWithStateUpdate(CoreKitAction.getPubKeyEd25519, {});
}
}

0 comments on commit 8394365

Please sign in to comment.