Skip to content

Commit

Permalink
fix: remove prv key
Browse files Browse the repository at this point in the history
  • Loading branch information
Charon-Fan committed Jul 17, 2024
1 parent 5fea8b9 commit 9fb630f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ describe("cardano-catalyst-request", () => {
path: "m/1852'/1815'/0'/2/0",
delegations: [
{
xfp: "52744703",
hdPath: "m/1694'/1815'/0'/0'/0'",
pubKey:
"a6a3c0447aeb9cc54cf6422ba32b294e5e1c3ef6d782f2acff4a70694c4d1663",
weight: 1,
},
{
xfp: "52744703",
hdPath: "m/1694'/1815'/1'/0'/0'",
weight: 3,
},
],
stakePub:
"ad4b948699193634a39dd56f779a2951a24779ad52aa7916f6912b8ec4702cee",
Expand All @@ -44,7 +39,7 @@ describe("cardano-catalyst-request", () => {

const ur = request.toUREncoder(1000).nextPart();
expect(ur).toBe(
"ur:cardano-catalyst-voting-registration/pdadtpdagdndcawmgtfrkigrpmndutdnbtkgfssbjnaolftaayoyoeadtaaddyoeadlecfamnnykcfatchykaeykaeykaeykaocygmjyflaxaoadtaayoyoeadtaaddyoeadlecfamnnykcfatchykadykaeykaeykaocygmjyflaxaoaxaxhdcxpmgrmwlnnlcfeneeotnttljlktnydtgyoeflkkpmgmpkkkcmynmednmnssjodwwyaahdesaehdmnmncacssbonkooxtehghdamnewlglguynetrpzsylrtkglerydnsksksnwyflrpbauoktjplpgudkspgdeoswetenfwbbsbztiydilonelyssahcyaegunsdnamaeattaaddyoeadlecfatfnykcfatchykaeykaowkaewkaocygmjyflaxayjtiahsjpiehsjtjldpkthsjzjzihjyrtmhkoee"
"ur:cardano-catalyst-voting-registration/pdadtpdagdndcawmgtfrkigrpmndutdnbtkgfssbjnaolytaayoyoeadhdcxolotrtfyknwmnsskgsynfwdnotdndtglhycefmyntslfwzpszmgejoingsgtcmiaaoadaxhdcxpmgrmwlnnlcfeneeotnttljlktnydtgyoeflkkpmgmpkkkcmynmednmnssjodwwyaahdesaehdmnmncacssbonkooxtehghdamnewlglguynetrpzsylrtkglerydnsksksnwyflrpbauoktjplpgudkspgdeoswetenfwbbsbztiydilonelyssahcyaegunsdnamaeattaaddyoeadlecfatfnykcfatchykaeykaowkaewkaocygmjyflaxayjtiahsjpiehsjtjldpkthsjzjzihjyvomsehee"
);
});
});
2 changes: 1 addition & 1 deletion packages/ur-registry-cardano/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@keystonehq/bc-ur-registry-cardano",
"version": "0.3.6",
"version": "0.3.7",
"description": "bc-ur-registry extension for Cardano",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/ur-registry-cardano/src/CardanoCatalystRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum Keys {
}

interface CardanoCatalystRawDelegationProps {
hdPath: string;
pubKey: string;
weight: number;
}

Expand Down Expand Up @@ -171,7 +171,7 @@ export class CardanoCatalystRequest extends RegistryItem {
: undefined;
const cardanoDelegations = delegations.map((delegation) =>
CardanoDelegation.constructCardanoDelegation({
hdPath: genCryptoKeypath(delegation.hdPath, xfp),
pubKey: Buffer.from(delegation.pubKey, "hex"),
weight: delegation.weight,
})
);
Expand Down
10 changes: 2 additions & 8 deletions packages/ur-registry-cardano/src/CardanoCatalystSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,23 @@ const { RegistryTypes, decodeToDataItem } = extend;
enum Keys {
requestId = 1,
signature,
votePrvKeys,
}

export class CardanoCatalystSignature extends RegistryItem {
private requestId?: Buffer;
private signature: Buffer;
private votePrvKeys: Buffer[] = [];

getRegistryType = () =>
ExtendedRegistryTypes.CARDANO_CATALYST_VOTING_REGISTRATION_SIGNATURE;

constructor(signature: Buffer, votePrvKeys: Buffer[], requestId?: Buffer) {
constructor(signature: Buffer, requestId?: Buffer) {
super();
this.signature = signature;
this.requestId = requestId;
this.votePrvKeys = votePrvKeys;
}

public getRequestId = () => this.requestId;
public getSignature = () => this.signature;
public getVotePrvKeys = () => this.votePrvKeys;

public toDataItem = () => {
const map: DataItemMap = {};
Expand All @@ -42,7 +38,6 @@ export class CardanoCatalystSignature extends RegistryItem {
);
}
map[Keys.signature] = this.getSignature();
map[Keys.votePrvKeys] = this.getVotePrvKeys();
return new DataItem(map);
};

Expand All @@ -52,8 +47,7 @@ export class CardanoCatalystSignature extends RegistryItem {
const requestId = map[Keys.requestId]
? map[Keys.requestId].getData()
: undefined;
const votePrvKeys = map[Keys.votePrvKeys];
return new CardanoCatalystSignature(signature, votePrvKeys, requestId);
return new CardanoCatalystSignature(signature, requestId);
};

public static fromCBOR = (_cborPayload: Buffer) => {
Expand Down
24 changes: 10 additions & 14 deletions packages/ur-registry-cardano/src/CardanoDelegation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
CryptoKeypath,
extend,
DataItem,
RegistryItem,
Expand All @@ -10,47 +9,44 @@ import { ExtendedRegistryTypes } from "./RegistryType";
const { decodeToDataItem } = extend;

export interface CardanoCatalystDelegationProps {
hdPath: CryptoKeypath;
pubKey: Buffer;
weight: number;
}

enum Keys {
hdPath = 1,
pubKey = 1,
weight,
}

export class CardanoDelegation extends RegistryItem {
private hdPath: CryptoKeypath;
private pubKey: Buffer;
private weight: number;

getRegistryType = () => ExtendedRegistryTypes.CARDANO_DELEGATION;

constructor(args: CardanoCatalystDelegationProps) {
super();
this.hdPath = args.hdPath;
this.pubKey = args.pubKey;
this.weight = args.weight;
}

public getHdPath = () => this.hdPath;
public getPubKey = () => this.pubKey;
public getWeight = () => this.weight;

public toDataItem = () => {
const map: DataItemMap = {};

const keyPath = this.getHdPath().toDataItem();
keyPath.setTag(this.getHdPath().getRegistryType().getTag());
map[Keys.hdPath] = keyPath;

map[Keys.pubKey] = this.getPubKey();
map[Keys.weight] = this.getWeight();

return new DataItem(map);
};

public static fromDataItem = (dataItem: DataItem) => {
const map = dataItem.getData();
const hdPath = CryptoKeypath.fromDataItem(map[Keys.hdPath]);
const pubKey = map[Keys.pubKey];
const weight = map[Keys.weight];
return new CardanoDelegation({ hdPath, weight });
return new CardanoDelegation({ pubKey, weight });
};

public static fromCBOR = (_cborPayload: Buffer) => {
Expand All @@ -59,9 +55,9 @@ export class CardanoDelegation extends RegistryItem {
};

public static constructCardanoDelegation({
hdPath,
pubKey,
weight,
}: CardanoCatalystDelegationProps) {
return new CardanoDelegation({ hdPath, weight });
return new CardanoDelegation({ pubKey, weight });
}
}

0 comments on commit 9fb630f

Please sign in to comment.