-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from KeystoneHQ/feat/ada-integration-v3
chore: update Cardano registry with new delegation type
- Loading branch information
Showing
5 changed files
with
132 additions
and
27 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/ur-registry-cardano/__tests__/CardanoCatalystRequest.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// @ts-nocheck | ||
|
||
import { CardanoCatalystRequest } from "../src"; | ||
import * as uuid from "uuid"; | ||
|
||
describe("cardano-catalyst-request", () => { | ||
it("test should generate cardano-catalyst-request", () => { | ||
const cardanoCatalystVotingRequest = { | ||
requestId: "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d", | ||
path: "m/1852'/1815'/0'/2/0", | ||
delegations: [ | ||
{ | ||
xfp: "52744703", | ||
hdPath: "m/1694'/1815'/0'/0'/0'", | ||
weight: 1, | ||
}, | ||
{ | ||
xfp: "52744703", | ||
hdPath: "m/1694'/1815'/1'/0'/0'", | ||
weight: 3, | ||
}, | ||
], | ||
stakePub: | ||
"ad4b948699193634a39dd56f779a2951a24779ad52aa7916f6912b8ec4702cee", | ||
paymentAddress: | ||
"00588e8e1d18cba576a4d35758069fe94e53f638b6faf7c07b8abd2bc5c5cdee47b60edc7772855324c85033c638364214cbfc6627889f81c4", | ||
nonce: 5479467, | ||
voting_purpose: 0, | ||
xfp: "52744703", | ||
origin: "cardano-wallet", | ||
}; | ||
|
||
const request = CardanoCatalystRequest.constructCardanoCatalystRequest( | ||
cardanoCatalystVotingRequest.delegations, | ||
cardanoCatalystVotingRequest.stakePub, | ||
cardanoCatalystVotingRequest.paymentAddress, | ||
cardanoCatalystVotingRequest.nonce, | ||
cardanoCatalystVotingRequest.voting_purpose, | ||
cardanoCatalystVotingRequest.path, | ||
cardanoCatalystVotingRequest.xfp, | ||
cardanoCatalystVotingRequest.requestId, | ||
cardanoCatalystVotingRequest.origin | ||
); | ||
|
||
const ur = request.toUREncoder(1000).nextPart(); | ||
expect(ur).toBe( | ||
"ur:cardano-catalyst-voting-registration/pdadtpdagdndcawmgtfrkigrpmndutdnbtkgfssbjnaolftaayoyoeadtaaddyoeadlecfamnnykcfatchykaeykaeykaeykaocygmjyflaxaoadtaayoyoeadtaaddyoeadlecfamnnykcfatchykadykaeykaeykaocygmjyflaxaoaxaxhdcxpmgrmwlnnlcfeneeotnttljlktnydtgyoeflkkpmgmpkkkcmynmednmnssjodwwyaahdesaehdmnmncacssbonkooxtehghdamnewlglguynetrpzsylrtkglerydnsksksnwyflrpbauoktjplpgudkspgdeoswetenfwbbsbztiydilonelyssahcyaegunsdnamaeattaaddyoeadlecfatfnykcfatchykaeykaowkaewkaocygmjyflaxayjtiahsjpiehsjtjldpkthsjzjzihjyrtmhkoee" | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
CryptoKeypath, | ||
extend, | ||
DataItem, | ||
RegistryItem, | ||
DataItemMap, | ||
} from "@keystonehq/bc-ur-registry"; | ||
import { ExtendedRegistryTypes } from "./RegistryType"; | ||
|
||
const { decodeToDataItem } = extend; | ||
|
||
export interface CardanoCatalystDelegationProps { | ||
hdPath: CryptoKeypath; | ||
weight: number; | ||
} | ||
|
||
enum Keys { | ||
hdPath = 1, | ||
weight, | ||
} | ||
|
||
export class CardanoDelegation extends RegistryItem { | ||
private hdPath: CryptoKeypath; | ||
private weight: number; | ||
|
||
getRegistryType = () => ExtendedRegistryTypes.CARDANO_DELEGATION; | ||
|
||
constructor(args: CardanoCatalystDelegationProps) { | ||
super(); | ||
this.hdPath = args.hdPath; | ||
this.weight = args.weight; | ||
} | ||
|
||
public getHdPath = () => this.hdPath; | ||
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.weight] = this.getWeight(); | ||
|
||
return new DataItem(map); | ||
}; | ||
|
||
public static fromDataItem = (dataItem: DataItem) => { | ||
const map = dataItem.getData(); | ||
const hdPath = CryptoKeypath.fromDataItem(map[Keys.hdPath]); | ||
const weight = map[Keys.weight]; | ||
return new CardanoDelegation({ hdPath, weight }); | ||
}; | ||
|
||
public static fromCBOR = (_cborPayload: Buffer) => { | ||
const dataItem = decodeToDataItem(_cborPayload); | ||
return CardanoDelegation.fromDataItem(dataItem); | ||
}; | ||
|
||
public static constructCardanoDelegation({ | ||
hdPath, | ||
weight, | ||
}: CardanoCatalystDelegationProps) { | ||
return new CardanoDelegation({ hdPath, weight }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters