Skip to content

Commit

Permalink
Merge pull request #42 from KeystoneHQ/add-version-to-multi-accounts
Browse files Browse the repository at this point in the history
Add version field to crypto multi account
  • Loading branch information
soralit authored Sep 28, 2023
2 parents 5a02ef0 + f5db43b commit 7d64aa9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
12 changes: 8 additions & 4 deletions __tests__/extended/CryptoMultiAccounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ describe("CryptoMultiAccount", () => {
Buffer.from("e9181cf3", "hex"),
[cryptoHDKey],
"keystone",
"28475c8d80f6c06bafbe46a7d1750f3fcf2565f7"
"28475c8d80f6c06bafbe46a7d1750f3fcf2565f7",
"1.0.2"
);
const hex = multiAccounts.toCBOR().toString("hex");
expect(hex).toBe(
"a4011ae9181cf30281d9012fa203582102eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b06d90130a10188182cf51901f5f500f500f503686b657973746f6e6504782832383437356338643830663663303662616662653436613764313735306633666366323536356637"
"a5011ae9181cf30281d9012fa203582102eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b06d90130a10188182cf51901f5f500f500f503686b657973746f6e65047828323834373563386438306636633036626166626534366137643137353066336663663235363566370565312e302e32"
);
const ur = multiAccounts.toUREncoder(1000).nextPart();
expect(ur).toBe(
"ur:crypto-multi-accounts/oxadcywlcscewfaolytaaddloeaxhdclaowdverokopdinhseeroisyalksaykctjshedprnuyjyfgrovawewftyghceglrpkgamtaaddyoyadlocsdwykcfadykykaeykaeykaxisjeihkkjkjyjljtihaaksdeeyeteeemeciaetieetdyiyeniadyenidhsiyidiheeenhsemieehemecdyiyeoiyiaiyeyeceneciyemwydrlpjt"
"ur:crypto-multi-accounts/onadcywlcscewfaolytaaddloeaxhdclaowdverokopdinhseeroisyalksaykctjshedprnuyjyfgrovawewftyghceglrpkgamtaaddyoyadlocsdwykcfadykykaeykaeykaxisjeihkkjkjyjljtihaaksdeeyeteeemeciaetieetdyiyeniadyenidhsiyidiheeenhsemieehemecdyiyeoiyiaiyeyeceneciyemahihehdmdydmeyksrlzmdi"
);
});

it("should decode CryptoMultiAccount", () => {
const hex =
"a4011ae9181cf30281d9012fa203582102eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b06d90130a10188182cf51901f5f500f500f503686b657973746f6e6504782832383437356338643830663663303662616662653436613764313735306633666366323536356637";
"a5011ae9181cf30281d9012fa203582102eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b06d90130a10188182cf51901f5f500f500f503686b657973746f6e65047828323834373563386438306636633036626166626534366137643137353066336663663235363566370565312e302e32";
const cryptoMultiAccounts = CryptoMultiAccounts.fromCBOR(
Buffer.from(hex, "hex")
);
Expand All @@ -54,5 +55,8 @@ describe("CryptoMultiAccount", () => {
expect(cryptoMultiAccounts.getDeviceId()).toBe(
"28475c8d80f6c06bafbe46a7d1750f3fcf2565f7"
);
expect(cryptoMultiAccounts.getVersion()).toBe(
"1.0.2"
);
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@keystonehq/bc-ur-registry",
"version": "0.6.3",
"version": "0.6.4",
"description": "A JS implementation of Uniform Resources(UR) Registry specification from Blockchain Commons",
"publishConfig": {
"access": "public"
Expand Down
11 changes: 9 additions & 2 deletions src/extended/CryptoMultiAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum Keys {
keys,
device,
deviceId,
version,
}

export class CryptoMultiAccounts extends RegistryItem {
Expand All @@ -17,7 +18,8 @@ export class CryptoMultiAccounts extends RegistryItem {
private masterFingerprint: Buffer,
private keys: CryptoHDKey[],
private device?: string,
private deviceId?: string
private deviceId?: string,
private version?: string
) {
super();
}
Expand All @@ -26,6 +28,7 @@ export class CryptoMultiAccounts extends RegistryItem {
public getKeys = () => this.keys;
public getDevice = () => this.device;
public getDeviceId = () => this.deviceId;
public getVersion = () => this.version;

public toDataItem = (): DataItem => {
const map: DataItemMap = {};
Expand All @@ -45,6 +48,9 @@ export class CryptoMultiAccounts extends RegistryItem {
if (this.deviceId) {
map[Keys.deviceId] = this.deviceId;
}
if (this.version) {
map[Keys.version] = this.version;
}
return new DataItem(map);
};

Expand All @@ -59,7 +65,8 @@ export class CryptoMultiAccounts extends RegistryItem {
const cryptoHDKeys = keys.map((item) => CryptoHDKey.fromDataItem(item));
const device = map[Keys.device];
const deviceId = map[Keys.deviceId];
return new CryptoMultiAccounts(masterFingerprint, cryptoHDKeys, device, deviceId);
const version = map[Keys.version];
return new CryptoMultiAccounts(masterFingerprint, cryptoHDKeys, device, deviceId, version);
};

public static fromCBOR = (_cborPayload: Buffer) => {
Expand Down

0 comments on commit 7d64aa9

Please sign in to comment.