Skip to content

Commit

Permalink
Merge pull request #41 from KeystoneHQ/add-device-id
Browse files Browse the repository at this point in the history
Add device id in crypto-multi-account
  • Loading branch information
renfengshi authored Jun 7, 2023
2 parents 2d38107 + 3086eaa commit 5a02ef0
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 @@ -22,21 +22,22 @@ describe("CryptoMultiAccount", () => {
const multiAccounts = new CryptoMultiAccounts(
Buffer.from("e9181cf3", "hex"),
[cryptoHDKey],
"keystone"
"keystone",
"28475c8d80f6c06bafbe46a7d1750f3fcf2565f7"
);
const hex = multiAccounts.toCBOR().toString("hex");
expect(hex).toBe(
"a3011ae9181cf30281d9012fa203582102eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b06d90130a10188182cf51901f5f500f500f503686b657973746f6e65"
"a4011ae9181cf30281d9012fa203582102eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b06d90130a10188182cf51901f5f500f500f503686b657973746f6e6504782832383437356338643830663663303662616662653436613764313735306633666366323536356637"
);
const ur = multiAccounts.toUREncoder(1000).nextPart();
expect(ur).toBe(
"ur:crypto-multi-accounts/otadcywlcscewfaolytaaddloeaxhdclaowdverokopdinhseeroisyalksaykctjshedprnuyjyfgrovawewftyghceglrpkgamtaaddyoyadlocsdwykcfadykykaeykaeykaxisjeihkkjkjyjljtiheokkkgkt"
"ur:crypto-multi-accounts/oxadcywlcscewfaolytaaddloeaxhdclaowdverokopdinhseeroisyalksaykctjshedprnuyjyfgrovawewftyghceglrpkgamtaaddyoyadlocsdwykcfadykykaeykaeykaxisjeihkkjkjyjljtihaaksdeeyeteeemeciaetieetdyiyeniadyenidhsiyidiheeenhsemieehemecdyiyeoiyiaiyeyeceneciyemwydrlpjt"
);
});

it("should decode CryptoMultiAccount", () => {
const hex =
"a3011ae9181cf30281d9012fa203582102eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b06d90130a10188182cf51901f5f500f500f503686b657973746f6e65";
"a4011ae9181cf30281d9012fa203582102eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b06d90130a10188182cf51901f5f500f500f503686b657973746f6e6504782832383437356338643830663663303662616662653436613764313735306633666366323536356637";
const cryptoMultiAccounts = CryptoMultiAccounts.fromCBOR(
Buffer.from(hex, "hex")
);
Expand All @@ -50,5 +51,8 @@ describe("CryptoMultiAccount", () => {
expect(cryptoMultiAccounts.getKeys()[0].getOrigin().getPath()).toBe(
"44'/501'/0'/0'"
);
expect(cryptoMultiAccounts.getDeviceId()).toBe(
"28475c8d80f6c06bafbe46a7d1750f3fcf2565f7"
);
});
});
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.2",
"version": "0.6.3",
"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 @@ -7,6 +7,7 @@ enum Keys {
masterFingerprint = 1,
keys,
device,
deviceId,
}

export class CryptoMultiAccounts extends RegistryItem {
Expand All @@ -15,14 +16,16 @@ export class CryptoMultiAccounts extends RegistryItem {
constructor(
private masterFingerprint: Buffer,
private keys: CryptoHDKey[],
private device?: string
private device?: string,
private deviceId?: string
) {
super();
}

public getMasterFingerprint = () => this.masterFingerprint;
public getKeys = () => this.keys;
public getDevice = () => this.device;
public getDeviceId = () => this.deviceId;

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

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

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

0 comments on commit 5a02ef0

Please sign in to comment.