Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions crypto/teddsa/teddsa_interface/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@oko-wallet/teddsa-interface",
"version": "0.0.1-alpha.0",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"publishConfig": {
"access": "public"
},
"scripts": {
"clean": "del-cli dist",
"build": "yarn clean && tsc && tsc-alias"
},
"devDependencies": {
"@types/node": "^24.10.1",
"del-cli": "^6.0.0",
"tsc-alias": "^1.8.16",
"typescript": "^5.8.3"
}
}
2 changes: 2 additions & 0 deletions crypto/teddsa/teddsa_interface/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./keygen";
export * from "./sign";
21 changes: 21 additions & 0 deletions crypto/teddsa/teddsa_interface/src/api/keygen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { TeddsaKeygenOutput } from "../keygen";

export interface TeddsaKeygenInitRequest {
user_id: string;
}

export interface TeddsaKeygenInitResponse {
session_id: string;
}

export interface TeddsaKeygenStoreRequest {
user_id: string;
session_id: string;
keygen_output: TeddsaKeygenOutput;
public_key: number[];
}

export interface TeddsaKeygenStoreResponse {
success: boolean;
public_key: number[];
}
34 changes: 34 additions & 0 deletions crypto/teddsa/teddsa_interface/src/api/sign.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type {
TeddsaCommitmentEntry,
TeddsaSignatureShareEntry,
} from "../sign";

export interface TeddsaSignRound1Request {
session_id: string;
message: number[];
client_commitment: TeddsaCommitmentEntry;
}

export interface TeddsaSignRound1Response {
server_commitment: TeddsaCommitmentEntry;
}

export interface TeddsaSignRound2Request {
session_id: string;
client_signature_share: TeddsaSignatureShareEntry;
}

export interface TeddsaSignRound2Response {
server_signature_share: TeddsaSignatureShareEntry;
}

export interface TeddsaAggregateRequest {
session_id: string;
message: number[];
all_commitments: TeddsaCommitmentEntry[];
all_signature_shares: TeddsaSignatureShareEntry[];
}

export interface TeddsaAggregateResponse {
signature: number[];
}
22 changes: 22 additions & 0 deletions crypto/teddsa/teddsa_interface/src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export type TeddsaErrorCode =
| "WASM_NOT_INITIALIZED"
| "WASM_INIT_FAILED"
| "KEYGEN_FAILED"
| "SIGN_ROUND1_FAILED"
| "SIGN_ROUND2_FAILED"
| "AGGREGATE_FAILED"
| "VERIFY_FAILED"
| "INVALID_INPUT"
| "SERIALIZATION_ERROR";

export class TeddsaException extends Error {
readonly code: TeddsaErrorCode;
readonly cause?: unknown;

constructor(code: TeddsaErrorCode, message: string, cause?: unknown) {
super(message);
this.name = "TeddsaException";
this.code = code;
this.cause = cause;
}
}
5 changes: 5 additions & 0 deletions crypto/teddsa/teddsa_interface/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./keygen";
export * from "./sign";
export * from "./participant";
export * from "./errors";
export * from "./api";
17 changes: 17 additions & 0 deletions crypto/teddsa/teddsa_interface/src/keygen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface TeddsaKeygenOutput {
key_package: number[];
public_key_package: number[];
identifier: number[];
}

export interface TeddsaCentralizedKeygenOutput {
private_key: number[];
keygen_outputs: TeddsaKeygenOutput[];
public_key: number[];
}

export interface TeddsaClientKeygenState {
keygen_1: TeddsaKeygenOutput | null;
keygen_2: TeddsaKeygenOutput | null;
public_key: number[] | null;
}
26 changes: 26 additions & 0 deletions crypto/teddsa/teddsa_interface/src/participant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Participant identifiers for 2-of-2 TEdDSA threshold scheme.
*
* In FROST 2-of-2 with IdentifierList::Default:
* - P0 (Client) = identifier 1
* - P1 (Server) = identifier 2
*/
export enum Participant {
/** Client participant (keygen_1, identifier = 1) */
P0 = 0,
/** Server participant (keygen_2, identifier = 2) */
P1 = 1,
}

/**
* Convert Participant enum to 32-byte FROST identifier.
*
* FROST identifiers are 32-byte scalars where:
* - P0 (Client): [1, 0, 0, ..., 0] (identifier 1)
* - P1 (Server): [2, 0, 0, ..., 0] (identifier 2)
*/
export function participantToIdentifier(participant: Participant): number[] {
const identifier = new Array(32).fill(0);
identifier[0] = participant === Participant.P0 ? 1 : 2;
return identifier;
}
36 changes: 36 additions & 0 deletions crypto/teddsa/teddsa_interface/src/sign.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export interface TeddsaSignRound1Output {
nonces: number[];
commitments: number[];
identifier: number[];
}

export interface TeddsaSignRound2Output {
signature_share: number[];
identifier: number[];
}

export interface TeddsaCommitmentEntry {
identifier: number[];
commitments: number[];
}

export interface TeddsaSignatureShareEntry {
identifier: number[];
signature_share: number[];
}

export interface TeddsaAggregateOutput {
signature: number[];
}

export interface TeddsaSignature {
signature: string;
}

export interface TeddsaClientSignState {
message: Uint8Array | null;
nonces: number[] | null;
commitments: number[] | null;
all_commitments: TeddsaCommitmentEntry[] | null;
all_signature_shares: TeddsaSignatureShareEntry[] | null;
}
17 changes: 17 additions & 0 deletions crypto/teddsa/teddsa_interface/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
"declarationMap": true,
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"crypto/teddsa/teddsa_wasm_mock",
"crypto/teddsa/teddsa_hooks_mock",
"crypto/teddsa/teddsa_keplr_addon_mock",
"crypto/teddsa/teddsa_interface",
"crypto/teddsa/frost_ed25519_keplr_wasm",
"sandbox/sandbox_sol"
]
Expand Down
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11183,6 +11183,17 @@ __metadata:
languageName: unknown
linkType: soft

"@oko-wallet/teddsa-interface@workspace:crypto/teddsa/teddsa_interface":
version: 0.0.0-use.local
resolution: "@oko-wallet/teddsa-interface@workspace:crypto/teddsa/teddsa_interface"
dependencies:
"@types/node": "npm:^24.10.1"
del-cli: "npm:^6.0.0"
tsc-alias: "npm:^1.8.16"
typescript: "npm:^5.8.3"
languageName: unknown
linkType: soft

"@oko-wallet/teddsa-keplr-addon-mock@workspace:crypto/teddsa/teddsa_keplr_addon_mock":
version: 0.0.0-use.local
resolution: "@oko-wallet/teddsa-keplr-addon-mock@workspace:crypto/teddsa/teddsa_keplr_addon_mock"
Expand Down