Skip to content

Commit

Permalink
chore: add in schnorr signing
Browse files Browse the repository at this point in the history
  • Loading branch information
dfx-json committed Oct 23, 2024
1 parent e47848c commit c6c26ae
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/agent/src/canisters/management.did
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ type http_request_result = record {
body : blob;
};

type schnorr_algorithm = variant {
bip340secp256k1;
ed25519;
};

type ecdsa_curve = variant {
secp256k1;
};
Expand Down Expand Up @@ -285,6 +290,27 @@ type sign_with_ecdsa_result = record {
signature : blob;
};

type schnorr_public_key_args = record {
canister_id : opt canister_id;
derivation_path : vec blob;
key_id : record { algorithm : schnorr_algorithm; name : text };
};

type schnorr_public_key_result = record {
public_key : blob;
chain_code : blob;
};

type sign_with_schnorr_args = record {
message : blob;
derivation_path : vec blob;
key_id : record { algorithm : schnorr_algorithm; name : text };
};

type sign_with_schnorr_result = record {
signature : blob;
};

type node_metrics_history_args = record {
subnet_id : principal;
start_at_timestamp_nanos : nat64;
Expand Down Expand Up @@ -389,6 +415,10 @@ service ic : {
ecdsa_public_key : (ecdsa_public_key_args) -> (ecdsa_public_key_result);
sign_with_ecdsa : (sign_with_ecdsa_args) -> (sign_with_ecdsa_result);

// Threshold Schnorr signature
schnorr_public_key : (schnorr_public_key_args) -> (schnorr_public_key_result);
sign_with_schnorr : (sign_with_schnorr_args) -> (sign_with_schnorr_result);

// bitcoin interface
bitcoin_get_balance : (bitcoin_get_balance_args) -> (bitcoin_get_balance_result);

Expand Down
29 changes: 29 additions & 0 deletions packages/agent/src/canisters/management_idl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ export default ({ IDL }) => {
amount: IDL.Nat,
});
const raw_rand_result = IDL.Vec(IDL.Nat8);
const schnorr_algorithm = IDL.Variant({
ed25519: IDL.Null,
bip340secp256k1: IDL.Null,
});
const schnorr_public_key_args = IDL.Record({
key_id: IDL.Record({
algorithm: schnorr_algorithm,
name: IDL.Text,
}),
canister_id: IDL.Opt(canister_id),
derivation_path: IDL.Vec(IDL.Vec(IDL.Nat8)),
});
const schnorr_public_key_result = IDL.Record({
public_key: IDL.Vec(IDL.Nat8),
chain_code: IDL.Vec(IDL.Nat8),
});
const sign_with_ecdsa_args = IDL.Record({
key_id: IDL.Record({ name: IDL.Text, curve: ecdsa_curve }),
derivation_path: IDL.Vec(IDL.Vec(IDL.Nat8)),
Expand All @@ -281,6 +297,17 @@ export default ({ IDL }) => {
const sign_with_ecdsa_result = IDL.Record({
signature: IDL.Vec(IDL.Nat8),
});
const sign_with_schnorr_args = IDL.Record({
key_id: IDL.Record({
algorithm: schnorr_algorithm,
name: IDL.Text,
}),
derivation_path: IDL.Vec(IDL.Vec(IDL.Nat8)),
message: IDL.Vec(IDL.Nat8),
});
const sign_with_schnorr_result = IDL.Record({
signature: IDL.Vec(IDL.Nat8),
});
const start_canister_args = IDL.Record({ canister_id: canister_id });
const stop_canister_args = IDL.Record({ canister_id: canister_id });
const stored_chunks_args = IDL.Record({ canister_id: canister_id });
Expand Down Expand Up @@ -343,7 +370,9 @@ export default ({ IDL }) => {
),
provisional_top_up_canister: IDL.Func([provisional_top_up_canister_args], [], []),
raw_rand: IDL.Func([], [raw_rand_result], []),
schnorr_public_key: IDL.Func([schnorr_public_key_args], [schnorr_public_key_result], []),
sign_with_ecdsa: IDL.Func([sign_with_ecdsa_args], [sign_with_ecdsa_result], []),
sign_with_schnorr: IDL.Func([sign_with_schnorr_args], [sign_with_schnorr_result], []),
start_canister: IDL.Func([start_canister_args], [], []),
stop_canister: IDL.Func([stop_canister_args], [], []),
stored_chunks: IDL.Func([stored_chunks_args], [stored_chunks_result], []),
Expand Down
20 changes: 20 additions & 0 deletions packages/agent/src/canisters/management_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,32 @@ export interface provisional_top_up_canister_args {
}
export type raw_rand_result = Uint8Array | number[];
export type satoshi = bigint;
export type schnorr_algorithm = { ed25519: null } | { bip340secp256k1: null };
export interface schnorr_public_key_args {
key_id: { algorithm: schnorr_algorithm; name: string };
canister_id: [] | [canister_id];
derivation_path: Array<Uint8Array | number[]>;
}
export interface schnorr_public_key_result {
public_key: Uint8Array | number[];
chain_code: Uint8Array | number[];
}
export interface sign_with_ecdsa_args {
key_id: { name: string; curve: ecdsa_curve };
derivation_path: Array<Uint8Array | number[]>;
message_hash: Uint8Array | number[];
}
export interface sign_with_schnorr_args {
key_id: { algorithm: schnorr_algorithm; name: string };
derivation_path: Array<Uint8Array | number[]>;
message: Uint8Array | number[];
}
export interface sign_with_ecdsa_result {
signature: Uint8Array | number[];
}
export interface sign_with_schnorr_result {
signature: Uint8Array | number[];
}
export interface snapshot {
id: snapshot_id;
total_size: bigint;
Expand Down Expand Up @@ -330,7 +348,9 @@ export default interface _SERVICE {
>;
provisional_top_up_canister: ActorMethod<[provisional_top_up_canister_args], undefined>;
raw_rand: ActorMethod<[], raw_rand_result>;
schnorr_public_key: ActorMethod<[schnorr_public_key_args], schnorr_public_key_result>;
sign_with_ecdsa: ActorMethod<[sign_with_ecdsa_args], sign_with_ecdsa_result>;
sign_with_schnorr: ActorMethod<[sign_with_schnorr_args], sign_with_schnorr_result>;
start_canister: ActorMethod<[start_canister_args], undefined>;
stop_canister: ActorMethod<[stop_canister_args], undefined>;
stored_chunks: ActorMethod<[stored_chunks_args], stored_chunks_result>;
Expand Down

0 comments on commit c6c26ae

Please sign in to comment.