@ledgerhq/device-trusted-app-kit-ledger-keyring-protocol 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/internal/utils/LKRPCommand.js +2 -2
- package/lib/cjs/internal/utils/LKRPCommand.js.map +3 -3
- package/lib/cjs/internal/utils/LKRPCommand.test.js +2 -2
- package/lib/cjs/internal/utils/LKRPCommand.test.js.map +3 -3
- package/lib/cjs/package.json +2 -2
- package/lib/esm/internal/utils/LKRPCommand.js +2 -2
- package/lib/esm/internal/utils/LKRPCommand.js.map +3 -3
- package/lib/esm/internal/utils/LKRPCommand.test.js +2 -2
- package/lib/esm/internal/utils/LKRPCommand.test.js.map +3 -3
- package/lib/esm/package.json +2 -2
- package/lib/types/internal/utils/LKRPCommand.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +5 -5
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var l=(
|
|
2
|
-
`))}getPublicKey(){switch(this.bytes[0]){case r.CommandTags.AddMember:case r.CommandTags.PublishKey:return this.parse().toMaybe().chain(e=>{switch(e.type){case r.CommandTags.AddMember:return(0,t.Just)(e.publicKey);case r.CommandTags.PublishKey:return(0,t.Just)(e.recipient);default:return t.Nothing}}).map(e=>(0,
|
|
1
|
+
"use strict";var m=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var l=(c,e)=>{for(var n in e)m(c,n,{get:e[n],enumerable:!0})},d=(c,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of p(e))!b.call(c,o)&&o!==n&&m(c,o,{get:()=>e[o],enumerable:!(i=f(e,o))||i.enumerable});return c};var h=c=>d(m({},"__esModule",{value:!0}),c);var B={};l(B,{LKRPCommand:()=>y});module.exports=h(B);var s=require("@ledgerhq/device-management-kit"),t=require("purify-ts"),r=require("../models/Tags"),a=require("./derivationPath"),u=require("./TLVParser");class y{constructor(e,n){this.bytes=e;this.data=n?(0,t.Just)((0,t.Right)(n)):t.Nothing}data;static fromHex(e){return new y((0,s.hexaStringToBuffer)(e)??new Uint8Array)}static fromData(e){const n=new s.ByteArrayBuilder;switch(e.type){case r.CommandTags.Seed:n.encodeInTLVFromBuffer(r.GeneralTags.Bytes,e.topic).encodeInTLVFromUInt16(r.GeneralTags.Int,e.protocolVersion).encodeInTLVFromBuffer(r.GeneralTags.PublicKey,e.groupKey).encodeInTLVFromBuffer(r.GeneralTags.Bytes,e.initializationVector).encodeInTLVFromBuffer(r.GeneralTags.Bytes,e.encryptedXpriv).encodeInTLVFromBuffer(r.GeneralTags.PublicKey,e.ephemeralPublicKey);break;case r.CommandTags.AddMember:{const o=new ArrayBuffer(4);new DataView(o).setUint32(0,e.permissions),n.encodeInTLVFromAscii(r.GeneralTags.String,e.name).encodeInTLVFromBuffer(r.GeneralTags.PublicKey,e.publicKey).encodeInTLVFromBuffer(r.GeneralTags.Int,new Uint8Array(o));break}case r.CommandTags.PublishKey:n.encodeInTLVFromBuffer(r.GeneralTags.Bytes,e.initializationVector).encodeInTLVFromBuffer(r.GeneralTags.Bytes,e.encryptedXpriv).encodeInTLVFromBuffer(r.GeneralTags.PublicKey,e.recipient).encodeInTLVFromBuffer(r.GeneralTags.PublicKey,e.ephemeralPublicKey);break;case r.CommandTags.Derive:n.encodeInTLVFromBuffer(r.GeneralTags.Bytes,(0,a.derivationPathAsBytes)(e.path)).encodeInTLVFromBuffer(r.GeneralTags.PublicKey,e.groupKey).encodeInTLVFromBuffer(r.GeneralTags.Bytes,e.initializationVector).encodeInTLVFromBuffer(r.GeneralTags.Bytes,e.encryptedXpriv).encodeInTLVFromBuffer(r.GeneralTags.PublicKey,e.ephemeralPublicKey);break}const i=n.build();return new y(new Uint8Array([e.type,i.length,...i]),e)}static bytesFromUnsignedData(e){const n=new s.ByteArrayBuilder;switch(e.type){case r.CommandTags.AddMember:{const o=new ArrayBuffer(4);new DataView(o).setUint32(0,e.permissions),n.encodeInTLVFromAscii(r.GeneralTags.String,e.name).encodeInTLVFromBuffer(r.GeneralTags.PublicKey,e.publicKey).encodeInTLVFromBuffer(r.GeneralTags.Int,new Uint8Array(o));break}case r.CommandTags.PublishKey:n.encodeInTLVFromBuffer(r.GeneralTags.Bytes,new Uint8Array).encodeInTLVFromBuffer(r.GeneralTags.Bytes,new Uint8Array).encodeInTLVFromBuffer(r.GeneralTags.PublicKey,e.recipient).encodeInTLVFromBuffer(r.GeneralTags.PublicKey,new Uint8Array);break;case r.CommandTags.Derive:n.encodeInTLVFromBuffer(r.GeneralTags.Bytes,(0,a.derivationPathAsBytes)(e.path));break}const i=n.build();return new Uint8Array([e.type,i.length,...i])}toString(){return(0,s.bufferToHexaString)(this.bytes,!1)}toU8A(){return this.bytes}parse(){return this.data.orDefaultLazy(()=>{const e=new u.TLVParser(this.bytes).parseCommandData();return this.data=(0,t.Just)(e),e})}toHuman(){return this.parse().map(e=>Object.entries(e).map(([n,i])=>n==="type"?`${r.CommandTags[i]}(0x${i?.toString(16).padStart(2,"0")}):`:` ${n}: ${i instanceof Uint8Array?(0,s.bufferToHexaString)(i,!1):i}`).join(`
|
|
2
|
+
`))}getPublicKey(){switch(this.bytes[0]){case r.CommandTags.AddMember:case r.CommandTags.PublishKey:return this.parse().toMaybe().chain(e=>{switch(e.type){case r.CommandTags.AddMember:return(0,t.Just)(e.publicKey);case r.CommandTags.PublishKey:return(0,t.Just)(e.recipient);default:return t.Nothing}}).map(e=>(0,s.bufferToHexaString)(e,!1));default:return t.Nothing}}getEncryptedPublishedKey(){switch(this.bytes[0]){case r.CommandTags.Seed:case r.CommandTags.Derive:case r.CommandTags.PublishKey:return this.parse().toMaybe().chain(e=>{switch(e.type){case r.CommandTags.Seed:case r.CommandTags.Derive:case r.CommandTags.PublishKey:return t.Maybe.of({...e});default:return t.Nothing}});default:return t.Nothing}}}0&&(module.exports={LKRPCommand});
|
|
3
3
|
//# sourceMappingURL=LKRPCommand.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/utils/LKRPCommand.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n bufferToHexaString,\n ByteArrayBuilder,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Just, Maybe, Nothing, Right } from \"purify-ts\";\n\nimport { type LKRPParsingError } from \"@api/model/Errors\";\nimport {\n type LKRPCommandData,\n type UnsignedCommandData,\n} from \"@internal/models/LKRPCommandTypes\";\nimport { CommandTags, GeneralTags } from \"@internal/models/Tags\";\nimport { type EncryptedPublishedKey } from \"@internal/models/Types\";\n\nimport { derivationPathAsBytes } from \"./derivationPath\";\nimport { TLVParser } from \"./TLVParser\";\n\nexport class LKRPCommand {\n private data: Maybe<Either<LKRPParsingError, LKRPCommandData>>;\n\n constructor(\n private bytes: Uint8Array,\n data?: LKRPCommandData,\n ) {\n this.data = data ? Just(Right(data)) : Nothing;\n }\n\n static fromHex(hex: string): LKRPCommand {\n return new LKRPCommand(hexaStringToBuffer(hex) ?? new Uint8Array());\n }\n\n static fromData(data: LKRPCommandData): LKRPCommand {\n const tlv = new ByteArrayBuilder();\n switch (data.type) {\n case CommandTags.Seed:\n tlv\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.topic)\n .encodeInTLVFromUInt16(GeneralTags.Int, data.protocolVersion)\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.groupKey)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.initializationVector)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.encryptedXpriv)\n .encodeInTLVFromBuffer(\n GeneralTags.PublicKey,\n data.ephemeralPublicKey,\n );\n break;\n\n case CommandTags.AddMember
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAIO,2CACPC,EAAyD,qBAOzDC,EAAyC,iCAGzCC,EAAsC,4BACtCC,EAA0B,uBAEnB,MAAMN,CAAY,CAGvB,YACUO,EACRC,EACA,CAFQ,WAAAD,EAGR,KAAK,KAAOC,KAAO,WAAK,SAAMA,CAAI,CAAC,EAAI,SACzC,CAPQ,KASR,OAAO,QAAQC,EAA0B,CACvC,OAAO,IAAIT,KAAY,sBAAmBS,CAAG,GAAK,IAAI,UAAY,CACpE,CAEA,OAAO,SAASD,EAAoC,CAClD,MAAME,EAAM,IAAI,mBAChB,OAAQF,EAAK,KAAM,CACjB,KAAK,cAAY,KACfE,EACG,sBAAsB,cAAY,MAAOF,EAAK,KAAK,EACnD,sBAAsB,cAAY,IAAKA,EAAK,eAAe,EAC3D,sBAAsB,cAAY,UAAWA,EAAK,QAAQ,EAC1D,sBAAsB,cAAY,MAAOA,EAAK,oBAAoB,EAClE,sBAAsB,cAAY,MAAOA,EAAK,cAAc,EAC5D,sBACC,cAAY,UACZA,EAAK,kBACP,EACF,MAEF,KAAK,cAAY,
|
|
6
|
-
"names": ["LKRPCommand_exports", "__export", "LKRPCommand", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_Tags", "import_derivationPath", "import_TLVParser", "bytes", "data", "hex", "tlv", "key", "value", "str"]
|
|
4
|
+
"sourcesContent": ["import {\n bufferToHexaString,\n ByteArrayBuilder,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Just, Maybe, Nothing, Right } from \"purify-ts\";\n\nimport { type LKRPParsingError } from \"@api/model/Errors\";\nimport {\n type LKRPCommandData,\n type UnsignedCommandData,\n} from \"@internal/models/LKRPCommandTypes\";\nimport { CommandTags, GeneralTags } from \"@internal/models/Tags\";\nimport { type EncryptedPublishedKey } from \"@internal/models/Types\";\n\nimport { derivationPathAsBytes } from \"./derivationPath\";\nimport { TLVParser } from \"./TLVParser\";\n\nexport class LKRPCommand {\n private data: Maybe<Either<LKRPParsingError, LKRPCommandData>>;\n\n constructor(\n private bytes: Uint8Array,\n data?: LKRPCommandData,\n ) {\n this.data = data ? Just(Right(data)) : Nothing;\n }\n\n static fromHex(hex: string): LKRPCommand {\n return new LKRPCommand(hexaStringToBuffer(hex) ?? new Uint8Array());\n }\n\n static fromData(data: LKRPCommandData): LKRPCommand {\n const tlv = new ByteArrayBuilder();\n switch (data.type) {\n case CommandTags.Seed:\n tlv\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.topic)\n .encodeInTLVFromUInt16(GeneralTags.Int, data.protocolVersion)\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.groupKey)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.initializationVector)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.encryptedXpriv)\n .encodeInTLVFromBuffer(\n GeneralTags.PublicKey,\n data.ephemeralPublicKey,\n );\n break;\n\n case CommandTags.AddMember: {\n const permissions = new ArrayBuffer(4);\n new DataView(permissions).setUint32(0, data.permissions);\n tlv\n .encodeInTLVFromAscii(GeneralTags.String, data.name)\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.publicKey)\n .encodeInTLVFromBuffer(GeneralTags.Int, new Uint8Array(permissions));\n break;\n }\n\n case CommandTags.PublishKey:\n tlv\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.initializationVector)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.encryptedXpriv)\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.recipient)\n .encodeInTLVFromBuffer(\n GeneralTags.PublicKey,\n data.ephemeralPublicKey,\n );\n break;\n\n case CommandTags.Derive:\n tlv\n .encodeInTLVFromBuffer(\n GeneralTags.Bytes,\n derivationPathAsBytes(data.path),\n )\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.groupKey)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.initializationVector)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.encryptedXpriv)\n .encodeInTLVFromBuffer(\n GeneralTags.PublicKey,\n data.ephemeralPublicKey,\n );\n break;\n }\n\n const bytes = tlv.build();\n return new LKRPCommand(\n new Uint8Array([data.type, bytes.length, ...bytes]),\n data,\n );\n }\n\n static bytesFromUnsignedData(data: UnsignedCommandData): Uint8Array {\n const tlv = new ByteArrayBuilder();\n switch (data.type) {\n case CommandTags.AddMember: {\n // NOTE: encode the permission bytes array with DataView because\n // ByteArrayBuilder.encodeInTLVFromUInt32 doesn't seem to work with negative numbers\n // ByteArrayBuilder.add32BitIntToData doesn't seem to work with number > 0x7fffffff\n const permissions = new ArrayBuffer(4);\n new DataView(permissions).setUint32(0, data.permissions);\n tlv\n .encodeInTLVFromAscii(GeneralTags.String, data.name)\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.publicKey)\n .encodeInTLVFromBuffer(GeneralTags.Int, new Uint8Array(permissions));\n break;\n }\n\n case CommandTags.PublishKey:\n tlv\n .encodeInTLVFromBuffer(GeneralTags.Bytes, new Uint8Array()) // Empty IV\n .encodeInTLVFromBuffer(GeneralTags.Bytes, new Uint8Array()) // Empty encryptedXpriv\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.recipient)\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, new Uint8Array()); // Empty ephemeralPublicKey\n break;\n\n case CommandTags.Derive:\n tlv.encodeInTLVFromBuffer(\n GeneralTags.Bytes,\n derivationPathAsBytes(data.path),\n );\n break;\n }\n\n const bytes = tlv.build();\n return new Uint8Array([data.type, bytes.length, ...bytes]);\n }\n\n toString(): string {\n return bufferToHexaString(this.bytes, false);\n }\n\n toU8A(): Uint8Array {\n return this.bytes;\n }\n\n parse(): Either<LKRPParsingError, LKRPCommandData> {\n return this.data.orDefaultLazy(() => {\n const data = new TLVParser(this.bytes).parseCommandData();\n this.data = Just(data);\n return data;\n });\n }\n\n toHuman(): Either<LKRPParsingError, string> {\n return this.parse().map((data) =>\n Object.entries(data)\n .map(([key, value]) => {\n if (key === \"type\") {\n return `${CommandTags[value as CommandTags]}(0x${value?.toString(16).padStart(2, \"0\")}):`;\n }\n return ` ${key}: ${value instanceof Uint8Array ? bufferToHexaString(value, false) : value}`;\n })\n .join(\"\\n\"),\n );\n }\n\n getPublicKey(): Maybe<string> {\n switch (this.bytes[0]) {\n case CommandTags.AddMember:\n case CommandTags.PublishKey:\n return this.parse()\n .toMaybe()\n .chain((data) => {\n switch (data.type) {\n case CommandTags.AddMember:\n return Just(data.publicKey);\n case CommandTags.PublishKey:\n return Just(data.recipient);\n default:\n return Nothing;\n }\n })\n .map((str) => bufferToHexaString(str, false));\n\n default:\n return Nothing;\n }\n }\n\n getEncryptedPublishedKey(): Maybe<EncryptedPublishedKey> {\n switch (this.bytes[0]) {\n case CommandTags.Seed:\n case CommandTags.Derive:\n case CommandTags.PublishKey:\n return this.parse()\n .toMaybe()\n .chain((data) => {\n switch (data.type) {\n case CommandTags.Seed:\n case CommandTags.Derive:\n case CommandTags.PublishKey:\n return Maybe.of({ ...data });\n default:\n return Nothing;\n }\n });\n default:\n return Nothing;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAIO,2CACPC,EAAyD,qBAOzDC,EAAyC,iCAGzCC,EAAsC,4BACtCC,EAA0B,uBAEnB,MAAMN,CAAY,CAGvB,YACUO,EACRC,EACA,CAFQ,WAAAD,EAGR,KAAK,KAAOC,KAAO,WAAK,SAAMA,CAAI,CAAC,EAAI,SACzC,CAPQ,KASR,OAAO,QAAQC,EAA0B,CACvC,OAAO,IAAIT,KAAY,sBAAmBS,CAAG,GAAK,IAAI,UAAY,CACpE,CAEA,OAAO,SAASD,EAAoC,CAClD,MAAME,EAAM,IAAI,mBAChB,OAAQF,EAAK,KAAM,CACjB,KAAK,cAAY,KACfE,EACG,sBAAsB,c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KAAK,cAAY,WACf,OAAO,KAAK,MAAM,EACf,QAAQ,EACR,MAAOL,GAAS,CACf,OAAQA,EAAK,KAAM,CACjB,KAAK,cAAY,UACf,SAAO,QAAKA,EAAK,SAAS,EAC5B,KAAK,cAAY,WACf,SAAO,QAAKA,EAAK,SAAS,EAC5B,QACE,OAAO,SACX,CACF,CAAC,EACA,IAAKM,MAAQ,sBAAmBA,EAAK,EAAK,CAAC,EAEhD,QACE,OAAO,SACX,CACF,CAEA,0BAAyD,CACvD,OAAQ,KAAK,MAAM,CAAC,EAAG,CACrB,KAAK,cAAY,KACjB,KAAK,cAAY,OACjB,KAAK,cAAY,WACf,OAAO,KAAK,MAAM,EACf,QAAQ,EACR,MAAON,GAAS,CACf,OAAQA,EAAK,KAAM,CACjB,KAAK,cAAY,KACjB,KAAK,cAAY,OACjB,KAAK,cAAY,WACf,OAAO,QAAM,GAAG,CAAE,GAAGA,CAAK,CAAC,EAC7B,QACE,OAAO,SACX,CACF,CAAC,EACL,QACE,OAAO,SACX,CACF,CACF",
|
|
6
|
+
"names": ["LKRPCommand_exports", "__export", "LKRPCommand", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_Tags", "import_derivationPath", "import_TLVParser", "bytes", "data", "hex", "tlv", "permissions", "key", "value", "str"]
|
|
7
7
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var r=require("purify-ts"),
|
|
2
|
-
`)))}),it("should fail for invalid command bytes format",()=>{const
|
|
1
|
+
"use strict";var r=require("purify-ts"),a=require("../../api/model/Errors"),c=require("../../api/model/Permissions"),x=require("../models/Tags"),t=require("./LKRPCommand");describe("LKRPCommand",()=>{describe("fromData",()=>{it("should encode add member permissions correctly",()=>{const e=Uint8Array.from([2,191,92,13,155,240,244,149,22,40,90,210,3,146,196,196,184,113,20,246,196,140,132,115,6,222,31,231,243,147,78,67,193]),n=t.LKRPCommand.fromData({type:x.CommandTags.AddMember,name:"OWNER",publicKey:e,permissions:c.Permissions.OWNER}),o=t.LKRPCommand.fromData({type:x.CommandTags.AddMember,name:"READER",publicKey:e,permissions:c.Permissions.CAN_ENCRYPT}),i=t.LKRPCommand.fromData({type:x.CommandTags.AddMember,name:"DAPP",publicKey:e,permissions:c.Permissions.OWNER&~c.Permissions.CAN_ADD_BLOCK});expect(n.toString()).toBe(["11 30","04 05 4f 57 4e 45 52","06 21 02 bf 5c 0d 9b f0 f4 95 16 28 5a d2 03 92 c4 c4 b8 71 14 f6 c4 8c 84 73 06 de 1f e7 f3 93 4e 43 c1","01 04 ff ff ff ff"].join("").replace(/ /g,"")),expect(o.toString()).toBe(["11 31","04 06 52 45 41 44 45 52","06 21 02 bf 5c 0d 9b f0 f4 95 16 28 5a d2 03 92 c4 c4 b8 71 14 f6 c4 8c 84 73 06 de 1f e7 f3 93 4e 43 c1","01 04 00 00 00 01"].join("").replace(/ /g,"")),expect(i.toString()).toBe(["11 2f","04 04 44 41 50 50","06 21 02 bf 5c 0d 9b f0 f4 95 16 28 5a d2 03 92 c4 c4 b8 71 14 f6 c4 8c 84 73 06 de 1f e7 f3 93 4e 43 c1","01 04 ff ff ff fb"].join("").replace(/ /g,""))})}),describe("bytesFromUnsignedData",()=>{it("should encode add member permissions correctly",()=>{const e=Uint8Array.from([2,191,92,13,155,240,244,149,22,40,90,210,3,146,196,196,184,113,20,246,196,140,132,115,6,222,31,231,243,147,78,67,193]),n=t.LKRPCommand.bytesFromUnsignedData({type:x.CommandTags.AddMember,name:"OWNER",publicKey:e,permissions:c.Permissions.OWNER}),o=t.LKRPCommand.bytesFromUnsignedData({type:x.CommandTags.AddMember,name:"READER",publicKey:e,permissions:c.Permissions.CAN_ENCRYPT}),i=t.LKRPCommand.bytesFromUnsignedData({type:x.CommandTags.AddMember,name:"DAPP",publicKey:e,permissions:c.Permissions.OWNER&~c.Permissions.CAN_ADD_BLOCK});expect(n).toEqual(Uint8Array.from([[17,48],[4,5,79,87,78,69,82],[6,33,2,191,92,13,155,240,244,149,22,40,90,210,3,146,196,196,184,113,20,246,196,140,132,115,6,222,31,231,243,147,78,67,193],[1,4,255,255,255,255]].flat())),expect(o).toEqual(Uint8Array.from([[17,49],[4,6,82,69,65,68,69,82],[6,33,2,191,92,13,155,240,244,149,22,40,90,210,3,146,196,196,184,113,20,246,196,140,132,115,6,222,31,231,243,147,78,67,193],[1,4,0,0,0,1]].flat())),expect(i).toEqual(Uint8Array.from([[17,47],[4,4,68,65,80,80],[6,33,2,191,92,13,155,240,244,149,22,40,90,210,3,146,196,196,184,113,20,246,196,140,132,115,6,222,31,231,243,147,78,67,193],[1,4,255,255,255,251]].flat()))})}),describe("toString",()=>{it("should return the hex of the bytes of the command",()=>{const e="0102030405060708",n=t.LKRPCommand.fromHex(e);expect(n.toString()).toBe(e)})}),describe("toU8A",()=>{it("should return the bytes of the command",()=>{const e=new Uint8Array([1,2,3,4,5,6,7,8]),n=new t.LKRPCommand(e);expect(n.toU8A()).toBe(e)})}),describe("parse",()=>{it("should parse the command data correctly",()=>{const e=new Uint8Array([x.GeneralTags.Bytes,3,1,2,3,x.GeneralTags.Int,2,1,2,x.GeneralTags.PublicKey,3,2,4,6,x.GeneralTags.Bytes,3,3,5,7,x.GeneralTags.Bytes,3,4,8,16,x.GeneralTags.PublicKey,3,10,11,12]),n=new t.LKRPCommand(new Uint8Array([x.CommandTags.Seed,e.length,...e]));expect(n.parse()).toStrictEqual((0,r.Right)({type:x.CommandTags.Seed,topic:new Uint8Array([1,2,3]),protocolVersion:258,groupKey:new Uint8Array([2,4,6]),initializationVector:new Uint8Array([3,5,7]),encryptedXpriv:new Uint8Array([4,8,16]),ephemeralPublicKey:new Uint8Array([10,11,12])}))}),it("should fail with invalid command bytes",()=>{const e=new t.LKRPCommand(new Uint8Array([x.CommandTags.Seed,1,1]));expect(e.parse()).toStrictEqual((0,r.Left)(new a.LKRPParsingError("Invalid end of TLV, expected length")))})}),describe("getPublicKey",()=>{it("should return the public key for AddMember command",()=>{const e=new Uint8Array([x.GeneralTags.String,3,65,66,67,x.GeneralTags.PublicKey,3,4,5,6,x.GeneralTags.Int,1,1]),n=new t.LKRPCommand(new Uint8Array([x.CommandTags.AddMember,e.length,...e]));expect(n.getPublicKey()).toStrictEqual((0,r.Just)("040506"))}),it("should return the public key for PublishKey commands",()=>{const e=new Uint8Array([x.GeneralTags.Bytes,3,1,2,3,x.GeneralTags.Bytes,3,4,5,6,x.GeneralTags.PublicKey,3,7,8,9,x.GeneralTags.PublicKey,3,10,11,12]),n=new t.LKRPCommand(new Uint8Array([x.CommandTags.PublishKey,e.length,...e]));expect(n.getPublicKey()).toEqual((0,r.Just)("070809"))}),it("should return undefined for other command types",()=>{const e=new t.LKRPCommand(new Uint8Array([x.CommandTags.Seed]));expect(e.getPublicKey()).toEqual(r.Nothing)})}),describe("toHuman",()=>{it("should return a string representation of the command",()=>{const e=new Uint8Array([x.GeneralTags.Bytes,3,1,2,3,x.GeneralTags.Bytes,3,4,5,6,x.GeneralTags.PublicKey,3,7,8,9,x.GeneralTags.PublicKey,3,10,11,12]),n=new t.LKRPCommand(new Uint8Array([x.CommandTags.PublishKey,e.length,...e]));expect(n.toHuman()).toStrictEqual((0,r.Right)(["PublishKey(0x12):"," initializationVector: 010203"," encryptedXpriv: 040506"," recipient: 070809"," ephemeralPublicKey: 0a0b0c"].join(`
|
|
2
|
+
`)))}),it("should fail for invalid command bytes format",()=>{const e=new t.LKRPCommand(new Uint8Array([x.CommandTags.Seed,1,1]));expect(e.toHuman()).toStrictEqual((0,r.Left)(new a.LKRPParsingError("Invalid end of TLV, expected length")))})})});
|
|
3
3
|
//# sourceMappingURL=LKRPCommand.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/utils/LKRPCommand.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { Just, Left, Nothing, Right } from \"purify-ts\";\n\nimport { LKRPParsingError } from \"@api/model/Errors\";\nimport { CommandTags, GeneralTags } from \"@internal/models/Tags\";\n\nimport { LKRPCommand } from \"./LKRPCommand\";\n\ndescribe(\"LKRPCommand\", () => {\n describe(\"toString\", () => {\n it(\"should return the hex of the bytes of the command\", () => {\n // WHEN\n const hex = \"0102030405060708\";\n const command = LKRPCommand.fromHex(hex);\n // THEN\n expect(command.toString()).toBe(hex);\n });\n });\n\n describe(\"toU8A\", () => {\n it(\"should return the bytes of the command\", () => {\n // WHEN\n const bytes = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);\n const command = new LKRPCommand(bytes);\n // THEN\n expect(command.toU8A()).toBe(bytes);\n });\n });\n\n describe(\"parse\", () => {\n it(\"should parse the command data correctly\", () => {\n // GIVEN\n const value = new Uint8Array([\n ...[GeneralTags.Bytes, 3, 0x01, 0x02, 0x03], // Topic\n ...[GeneralTags.Int, 2, 0x01, 0x02], // Protocol Version\n ...[GeneralTags.PublicKey, 3, 0x02, 0x04, 0x06], // Group Key\n ...[GeneralTags.Bytes, 3, 0x03, 0x05, 0x07], // Initialization Vector\n ...[GeneralTags.Bytes, 3, 0x04, 0x08, 0x10], // Encrypted xpriv\n ...[GeneralTags.PublicKey, 3, 0x0a, 0x0b, 0x0c], // Ephemeral Public Key\n ]);\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.Seed, value.length, ...value]),\n );\n // THEN\n expect(command.parse()).toStrictEqual(\n Right({\n type: CommandTags.Seed,\n topic: new Uint8Array([0x01, 0x02, 0x03]),\n protocolVersion: 258,\n groupKey: new Uint8Array([0x02, 0x04, 0x06]),\n initializationVector: new Uint8Array([0x03, 0x05, 0x07]),\n encryptedXpriv: new Uint8Array([0x04, 0x08, 0x10]),\n ephemeralPublicKey: new Uint8Array([0x0a, 0x0b, 0x0c]),\n }),\n );\n });\n\n it(\"should fail with invalid command bytes\", () => {\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.Seed, 1, ...[0x01]]),\n );\n // THEN\n expect(command.parse()).toStrictEqual(\n Left(new LKRPParsingError(\"Invalid end of TLV, expected length\")),\n );\n });\n });\n\n describe(\"getPublicKey\", () => {\n it(\"should return the public key for AddMember command\", () => {\n // GIVEN\n const addMemberValue = new Uint8Array([\n ...[GeneralTags.String, 3, 0x41, 0x42, 0x43], // Name \"ABC\"\n ...[GeneralTags.PublicKey, 3, 0x04, 0x05, 0x06], // Public Key\n ...[GeneralTags.Int, 1, 0x01], // Permissions\n ]);\n\n // WHEN\n const addMemberCmd = new LKRPCommand(\n new Uint8Array([\n CommandTags.AddMember,\n addMemberValue.length,\n ...addMemberValue,\n ]),\n );\n\n // THEN\n expect(addMemberCmd.getPublicKey()).toStrictEqual(Just(\"040506\"));\n });\n\n it(\"should return the public key for PublishKey commands\", () => {\n // GIVEN\n const publishKeyValue = new Uint8Array([\n ...[GeneralTags.Bytes, 3, 0x01, 0x02, 0x03], // Initialization Vector\n ...[GeneralTags.Bytes, 3, 0x04, 0x05, 0x06], // Encrypted xpriv\n ...[GeneralTags.PublicKey, 3, 0x07, 0x08, 0x09], // Recipient\n ...[GeneralTags.PublicKey, 3, 0x0a, 0x0b, 0x0c], // Ephemeral Public Key\n ]);\n // WHEN\n const publishKeyCmd = new LKRPCommand(\n new Uint8Array([\n CommandTags.PublishKey,\n publishKeyValue.length,\n ...publishKeyValue,\n ]),\n );\n // THEN\n expect(publishKeyCmd.getPublicKey()).toEqual(Just(\"070809\"));\n });\n\n it(\"should return undefined for other command types\", () => {\n // WHEN\n const command = new LKRPCommand(new Uint8Array([CommandTags.Seed]));\n // THEN\n expect(command.getPublicKey()).toEqual(Nothing);\n });\n });\n\n describe(\"toHuman\", () => {\n it(\"should return a string representation of the command\", () => {\n // GIVEN\n const value = new Uint8Array([\n ...[GeneralTags.Bytes, 3, 0x01, 0x02, 0x03], // Initialization Vector\n ...[GeneralTags.Bytes, 3, 0x04, 0x05, 0x06], // Encrypted xpriv\n ...[GeneralTags.PublicKey, 3, 0x07, 0x08, 0x09], // Recipient\n ...[GeneralTags.PublicKey, 3, 0x0a, 0x0b, 0x0c], // Ephemeral Public Key\n ]);\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.PublishKey, value.length, ...value]),\n );\n // THEN\n expect(command.toHuman()).toStrictEqual(\n Right(\n [\n `PublishKey(0x12):`,\n ` initializationVector: 010203`,\n ` encryptedXpriv: 040506`,\n ` recipient: 070809`,\n ` ephemeralPublicKey: 0a0b0c`,\n ].join(\"\\n\"),\n ),\n );\n });\n\n it(\"should fail for invalid command bytes format\", () => {\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.Seed, 1, ...[0x01]]),\n );\n // THEN\n expect(command.toHuman()).toStrictEqual(\n Left(new LKRPParsingError(\"Invalid end of TLV, expected length\")),\n );\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "aAAA,IAAAA,EAA2C,qBAE3CC,EAAiC,6BACjCC,EAAyC,iCAEzCC,EAA4B,yBAE5B,SAAS,cAAe,IAAM,CAC5B,SAAS,WAAY,IAAM,CACzB,GAAG,oDAAqD,IAAM,CAE5D,MAAMC,EAAM,mBACNC,EAAU,cAAY,QAAQD,CAAG,EAEvC,OAAOC,EAAQ,SAAS,CAAC,EAAE,KAAKD,CAAG,CACrC,CAAC,CACH,CAAC,EAED,SAAS,QAAS,IAAM,CACtB,GAAG,yCAA0C,IAAM,CAEjD,MAAME,EAAQ,IAAI,WAAW,CAAC,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,CAAC,CAAC,EAC/CD,EAAU,IAAI,cAAYC,CAAK,EAErC,OAAOD,EAAQ,MAAM,CAAC,EAAE,KAAKC,CAAK,CACpC,CAAC,CACH,CAAC,EAED,SAAS,QAAS,IAAM,CACtB,GAAG,0CAA2C,IAAM,CAElD,MAAMC,EAAQ,IAAI,WAAW,CACvB,cAAY,MAAO,EAAG,EAAM,EAAM,EAClC,cAAY,IAAK,EAAG,EAAM,EAC1B,cAAY,UAAW,EAAG,EAAM,EAAM,EACtC,cAAY,MAAO,EAAG,EAAM,EAAM,EA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"hex", "command", "bytes", "value", "addMemberValue", "addMemberCmd", "publishKeyValue", "publishKeyCmd"]
|
|
4
|
+
"sourcesContent": ["import { Just, Left, Nothing, Right } from \"purify-ts\";\n\nimport { LKRPParsingError } from \"@api/model/Errors\";\nimport { Permissions } from \"@api/model/Permissions\";\nimport { CommandTags, GeneralTags } from \"@internal/models/Tags\";\n\nimport { LKRPCommand } from \"./LKRPCommand\";\n\ndescribe(\"LKRPCommand\", () => {\n describe(\"fromData\", () => {\n it(\"should encode add member permissions correctly\", () => {\n // GIVEN\n const publicKey = Uint8Array.from([\n 0x02, 0xbf, 0x5c, 0x0d, 0x9b, 0xf0, 0xf4, 0x95, 0x16, 0x28, 0x5a, 0xd2,\n 0x03, 0x92, 0xc4, 0xc4, 0xb8, 0x71, 0x14, 0xf6, 0xc4, 0x8c, 0x84, 0x73,\n 0x06, 0xde, 0x1f, 0xe7, 0xf3, 0x93, 0x4e, 0x43, 0xc1,\n ]);\n // WHEN\n const addOwner = LKRPCommand.fromData({\n type: CommandTags.AddMember,\n name: \"OWNER\",\n publicKey,\n permissions: Permissions.OWNER,\n });\n const addReader = LKRPCommand.fromData({\n type: CommandTags.AddMember,\n name: \"READER\",\n publicKey,\n permissions: Permissions.CAN_ENCRYPT,\n });\n const dapp = LKRPCommand.fromData({\n type: CommandTags.AddMember,\n name: \"DAPP\",\n publicKey,\n permissions: Permissions.OWNER & ~Permissions.CAN_ADD_BLOCK,\n });\n // THEN\n expect(addOwner.toString()).toBe(\n [\n \"11 30\", // header\n \"04 05 4f 57 4e 45 52\", // name\n \"06 21 02 bf 5c 0d 9b f0 f4 95 16 28 5a d2 03 92 c4 c4 b8 71 14 f6 c4 8c 84 73 06 de 1f e7 f3 93 4e 43 c1\", // public key\n \"01 04 ff ff ff ff\", // permissions (OWNER)\n ]\n .join(\"\")\n .replace(/ /g, \"\"),\n );\n expect(addReader.toString()).toBe(\n [\n \"11 31\", // header\n \"04 06 52 45 41 44 45 52\", // name\n \"06 21 02 bf 5c 0d 9b f0 f4 95 16 28 5a d2 03 92 c4 c4 b8 71 14 f6 c4 8c 84 73 06 de 1f e7 f3 93 4e 43 c1\", // public key\n \"01 04 00 00 00 01\", // permissions (CAN_ENCRYPT)\n ]\n .join(\"\")\n .replace(/ /g, \"\"),\n );\n expect(dapp.toString()).toBe(\n [\n \"11 2f\", // header\n \"04 04 44 41 50 50\", // name\n \"06 21 02 bf 5c 0d 9b f0 f4 95 16 28 5a d2 03 92 c4 c4 b8 71 14 f6 c4 8c 84 73 06 de 1f e7 f3 93 4e 43 c1\", // public key\n \"01 04 ff ff ff fb\", // permissions (OWNER & ~CAN_ADD_BLOCK)\n ]\n .join(\"\")\n .replace(/ /g, \"\"),\n );\n });\n });\n\n describe(\"bytesFromUnsignedData\", () => {\n it(\"should encode add member permissions correctly\", () => {\n // GIVEN\n const publicKey = Uint8Array.from([\n 0x02, 0xbf, 0x5c, 0x0d, 0x9b, 0xf0, 0xf4, 0x95, 0x16, 0x28, 0x5a, 0xd2,\n 0x03, 0x92, 0xc4, 0xc4, 0xb8, 0x71, 0x14, 0xf6, 0xc4, 0x8c, 0x84, 0x73,\n 0x06, 0xde, 0x1f, 0xe7, 0xf3, 0x93, 0x4e, 0x43, 0xc1,\n ]);\n // WHEN\n const addOwner = LKRPCommand.bytesFromUnsignedData({\n type: CommandTags.AddMember,\n name: \"OWNER\",\n publicKey,\n permissions: Permissions.OWNER,\n });\n const addReader = LKRPCommand.bytesFromUnsignedData({\n type: CommandTags.AddMember,\n name: \"READER\",\n publicKey,\n permissions: Permissions.CAN_ENCRYPT,\n });\n const dapp = LKRPCommand.bytesFromUnsignedData({\n type: CommandTags.AddMember,\n name: \"DAPP\",\n publicKey,\n permissions: Permissions.OWNER & ~Permissions.CAN_ADD_BLOCK,\n });\n // THEN\n expect(addOwner).toEqual(\n Uint8Array.from(\n [\n [0x11, 0x30], // header\n [0x04, 0x05, 0x4f, 0x57, 0x4e, 0x45, 0x52], // name\n [\n // public key\n 0x06, 0x21, 0x02, 0xbf, 0x5c, 0x0d, 0x9b, 0xf0, 0xf4, 0x95, 0x16,\n 0x28, 0x5a, 0xd2, 0x03, 0x92, 0xc4, 0xc4, 0xb8, 0x71, 0x14, 0xf6,\n 0xc4, 0x8c, 0x84, 0x73, 0x06, 0xde, 0x1f, 0xe7, 0xf3, 0x93, 0x4e,\n 0x43, 0xc1,\n ],\n [0x01, 0x04, 0xff, 0xff, 0xff, 0xff], // permissions (OWNER)\n ].flat(),\n ),\n );\n expect(addReader).toEqual(\n Uint8Array.from(\n [\n [0x11, 0x31], // header\n [0x04, 0x06, 0x52, 0x45, 0x41, 0x44, 0x45, 0x52], // name\n [\n // public key\n 0x06, 0x21, 0x02, 0xbf, 0x5c, 0x0d, 0x9b, 0xf0, 0xf4, 0x95, 0x16,\n 0x28, 0x5a, 0xd2, 0x03, 0x92, 0xc4, 0xc4, 0xb8, 0x71, 0x14, 0xf6,\n 0xc4, 0x8c, 0x84, 0x73, 0x06, 0xde, 0x1f, 0xe7, 0xf3, 0x93, 0x4e,\n 0x43, 0xc1,\n ],\n [0x01, 0x04, 0x00, 0x00, 0x00, 0x01], // permissions (CAN_ENCRYPT)\n ].flat(),\n ),\n );\n expect(dapp).toEqual(\n Uint8Array.from(\n [\n [0x11, 0x2f], // header\n [0x04, 0x04, 0x44, 0x41, 0x50, 0x50], // name\n [\n // public key\n 0x06, 0x21, 0x02, 0xbf, 0x5c, 0x0d, 0x9b, 0xf0, 0xf4, 0x95, 0x16,\n 0x28, 0x5a, 0xd2, 0x03, 0x92, 0xc4, 0xc4, 0xb8, 0x71, 0x14, 0xf6,\n 0xc4, 0x8c, 0x84, 0x73, 0x06, 0xde, 0x1f, 0xe7, 0xf3, 0x93, 0x4e,\n 0x43, 0xc1,\n ],\n [0x01, 0x04, 0xff, 0xff, 0xff, 0xfb], // permissions (OWNER & ~CAN_ADD_BLOCK)\n ].flat(),\n ),\n );\n });\n });\n\n describe(\"toString\", () => {\n it(\"should return the hex of the bytes of the command\", () => {\n // WHEN\n const hex = \"0102030405060708\";\n const command = LKRPCommand.fromHex(hex);\n // THEN\n expect(command.toString()).toBe(hex);\n });\n });\n\n describe(\"toU8A\", () => {\n it(\"should return the bytes of the command\", () => {\n // WHEN\n const bytes = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);\n const command = new LKRPCommand(bytes);\n // THEN\n expect(command.toU8A()).toBe(bytes);\n });\n });\n\n describe(\"parse\", () => {\n it(\"should parse the command data correctly\", () => {\n // GIVEN\n const value = new Uint8Array([\n ...[GeneralTags.Bytes, 3, 0x01, 0x02, 0x03], // Topic\n ...[GeneralTags.Int, 2, 0x01, 0x02], // Protocol Version\n ...[GeneralTags.PublicKey, 3, 0x02, 0x04, 0x06], // Group Key\n ...[GeneralTags.Bytes, 3, 0x03, 0x05, 0x07], // Initialization Vector\n ...[GeneralTags.Bytes, 3, 0x04, 0x08, 0x10], // Encrypted xpriv\n ...[GeneralTags.PublicKey, 3, 0x0a, 0x0b, 0x0c], // Ephemeral Public Key\n ]);\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.Seed, value.length, ...value]),\n );\n // THEN\n expect(command.parse()).toStrictEqual(\n Right({\n type: CommandTags.Seed,\n topic: new Uint8Array([0x01, 0x02, 0x03]),\n protocolVersion: 258,\n groupKey: new Uint8Array([0x02, 0x04, 0x06]),\n initializationVector: new Uint8Array([0x03, 0x05, 0x07]),\n encryptedXpriv: new Uint8Array([0x04, 0x08, 0x10]),\n ephemeralPublicKey: new Uint8Array([0x0a, 0x0b, 0x0c]),\n }),\n );\n });\n\n it(\"should fail with invalid command bytes\", () => {\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.Seed, 1, ...[0x01]]),\n );\n // THEN\n expect(command.parse()).toStrictEqual(\n Left(new LKRPParsingError(\"Invalid end of TLV, expected length\")),\n );\n });\n });\n\n describe(\"getPublicKey\", () => {\n it(\"should return the public key for AddMember command\", () => {\n // GIVEN\n const addMemberValue = new Uint8Array([\n ...[GeneralTags.String, 3, 0x41, 0x42, 0x43], // Name \"ABC\"\n ...[GeneralTags.PublicKey, 3, 0x04, 0x05, 0x06], // Public Key\n ...[GeneralTags.Int, 1, 0x01], // Permissions\n ]);\n\n // WHEN\n const addMemberCmd = new LKRPCommand(\n new Uint8Array([\n CommandTags.AddMember,\n addMemberValue.length,\n ...addMemberValue,\n ]),\n );\n\n // THEN\n expect(addMemberCmd.getPublicKey()).toStrictEqual(Just(\"040506\"));\n });\n\n it(\"should return the public key for PublishKey commands\", () => {\n // GIVEN\n const publishKeyValue = new Uint8Array([\n ...[GeneralTags.Bytes, 3, 0x01, 0x02, 0x03], // Initialization Vector\n ...[GeneralTags.Bytes, 3, 0x04, 0x05, 0x06], // Encrypted xpriv\n ...[GeneralTags.PublicKey, 3, 0x07, 0x08, 0x09], // Recipient\n ...[GeneralTags.PublicKey, 3, 0x0a, 0x0b, 0x0c], // Ephemeral Public Key\n ]);\n // WHEN\n const publishKeyCmd = new LKRPCommand(\n new Uint8Array([\n CommandTags.PublishKey,\n publishKeyValue.length,\n ...publishKeyValue,\n ]),\n );\n // THEN\n expect(publishKeyCmd.getPublicKey()).toEqual(Just(\"070809\"));\n });\n\n it(\"should return undefined for other command types\", () => {\n // WHEN\n const command = new LKRPCommand(new Uint8Array([CommandTags.Seed]));\n // THEN\n expect(command.getPublicKey()).toEqual(Nothing);\n });\n });\n\n describe(\"toHuman\", () => {\n it(\"should return a string representation of the command\", () => {\n // GIVEN\n const value = new Uint8Array([\n ...[GeneralTags.Bytes, 3, 0x01, 0x02, 0x03], // Initialization Vector\n ...[GeneralTags.Bytes, 3, 0x04, 0x05, 0x06], // Encrypted xpriv\n ...[GeneralTags.PublicKey, 3, 0x07, 0x08, 0x09], // Recipient\n ...[GeneralTags.PublicKey, 3, 0x0a, 0x0b, 0x0c], // Ephemeral Public Key\n ]);\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.PublishKey, value.length, ...value]),\n );\n // THEN\n expect(command.toHuman()).toStrictEqual(\n Right(\n [\n `PublishKey(0x12):`,\n ` initializationVector: 010203`,\n ` encryptedXpriv: 040506`,\n ` recipient: 070809`,\n ` ephemeralPublicKey: 0a0b0c`,\n ].join(\"\\n\"),\n ),\n );\n });\n\n it(\"should fail for invalid command bytes format\", () => {\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.Seed, 1, ...[0x01]]),\n );\n // THEN\n expect(command.toHuman()).toStrictEqual(\n Left(new LKRPParsingError(\"Invalid end of TLV, expected length\")),\n );\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAA2C,qBAE3CC,EAAiC,6BACjCC,EAA4B,kCAC5BC,EAAyC,iCAEzCC,EAA4B,yBAE5B,SAAS,cAAe,IAAM,CAC5B,SAAS,WAAY,IAAM,CACzB,GAAG,iDAAkD,IAAM,CAEzD,MAAMC,EAAY,WAAW,KAAK,CAChC,EAAM,IAAM,GAAM,GAAM,IAAM,IAAM,IAAM,IAAM,GAAM,GAAM,GAAM,IAClE,EAAM,IAAM,IAAM,IAAM,IAAM,IAAM,GAAM,IAAM,IAAM,IAAM,IAAM,IAClE,EAAM,IAAM,GAAM,IAAM,IAAM,IAAM,GAAM,GAAM,GAClD,CAAC,EAEKC,EAAW,cAAY,SAAS,CACpC,KAAM,cAAY,UAClB,KAAM,QACN,UAAAD,EACA,YAAa,cAAY,KAC3B,CAAC,EACKE,EAAY,cAAY,SAAS,CACrC,KAAM,cAAY,UAClB,KAAM,SACN,UAAAF,EACA,YAAa,cAAY,WAC3B,CAAC,EACKG,EAAO,cAAY,SAAS,CAChC,KAAM,cAAY,UAClB,KAAM,OACN,UAAAH,EACA,YAAa,cAAY,MAAQ,CAAC,cAAY,aAChD,CAAC,EAED,OAAOC,EAAS,SAAS,CAAC,EAAE,KAC1B,CACE,QACA,uBACA,2GACA,mBACF,EACG,KAAK,EAAE,EACP,QAAQ,KAAM,EAAE,CACrB,EACA,OAAOC,EAAU,SAAS,CAAC,E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AC,EAED,GAAG,+CAAgD,IAAM,CAEvD,MAAMA,EAAU,IAAI,cAClB,IAAI,WAAW,CAAC,cAAY,KAAM,EAAO,CAAK,CAAC,CACjD,EAEA,OAAOA,EAAQ,QAAQ,CAAC,EAAE,iBACxB,QAAK,IAAI,mBAAiB,qCAAqC,CAAC,CAClE,CACF,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_purify_ts", "import_Errors", "import_Permissions", "import_Tags", "import_LKRPCommand", "publicKey", "addOwner", "addReader", "dapp", "hex", "command", "bytes", "value", "addMemberValue", "addMemberCmd", "publishKeyValue", "publishKeyCmd"]
|
|
7
7
|
}
|
package/lib/cjs/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/device-trusted-app-kit-ledger-keyring-protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"exports": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@ledgerhq/device-management-kit": "workspace:*",
|
|
39
|
-
"@ledgerhq/signer-utils": "
|
|
39
|
+
"@ledgerhq/signer-utils": "^1.1.0",
|
|
40
40
|
"@noble/ciphers": "^1.3.0",
|
|
41
41
|
"@noble/curves": "^1.9.7",
|
|
42
42
|
"@noble/hashes": "^1.8.0",
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{bufferToHexaString as
|
|
2
|
-
`))}getPublicKey(){switch(this.bytes[0]){case n.AddMember:case n.PublishKey:return this.parse().toMaybe().chain(e=>{switch(e.type){case n.AddMember:return
|
|
1
|
+
import{bufferToHexaString as y,ByteArrayBuilder as a,hexaStringToBuffer as f}from"@ledgerhq/device-management-kit";import{Just as c,Maybe as p,Nothing as s,Right as b}from"purify-ts";import{CommandTags as n,GeneralTags as r}from"../models/Tags";import{derivationPathAsBytes as u}from"./derivationPath";import{TLVParser as l}from"./TLVParser";class m{constructor(e,t){this.bytes=e;this.data=t?c(b(t)):s}data;static fromHex(e){return new m(f(e)??new Uint8Array)}static fromData(e){const t=new a;switch(e.type){case n.Seed:t.encodeInTLVFromBuffer(r.Bytes,e.topic).encodeInTLVFromUInt16(r.Int,e.protocolVersion).encodeInTLVFromBuffer(r.PublicKey,e.groupKey).encodeInTLVFromBuffer(r.Bytes,e.initializationVector).encodeInTLVFromBuffer(r.Bytes,e.encryptedXpriv).encodeInTLVFromBuffer(r.PublicKey,e.ephemeralPublicKey);break;case n.AddMember:{const o=new ArrayBuffer(4);new DataView(o).setUint32(0,e.permissions),t.encodeInTLVFromAscii(r.String,e.name).encodeInTLVFromBuffer(r.PublicKey,e.publicKey).encodeInTLVFromBuffer(r.Int,new Uint8Array(o));break}case n.PublishKey:t.encodeInTLVFromBuffer(r.Bytes,e.initializationVector).encodeInTLVFromBuffer(r.Bytes,e.encryptedXpriv).encodeInTLVFromBuffer(r.PublicKey,e.recipient).encodeInTLVFromBuffer(r.PublicKey,e.ephemeralPublicKey);break;case n.Derive:t.encodeInTLVFromBuffer(r.Bytes,u(e.path)).encodeInTLVFromBuffer(r.PublicKey,e.groupKey).encodeInTLVFromBuffer(r.Bytes,e.initializationVector).encodeInTLVFromBuffer(r.Bytes,e.encryptedXpriv).encodeInTLVFromBuffer(r.PublicKey,e.ephemeralPublicKey);break}const i=t.build();return new m(new Uint8Array([e.type,i.length,...i]),e)}static bytesFromUnsignedData(e){const t=new a;switch(e.type){case n.AddMember:{const o=new ArrayBuffer(4);new DataView(o).setUint32(0,e.permissions),t.encodeInTLVFromAscii(r.String,e.name).encodeInTLVFromBuffer(r.PublicKey,e.publicKey).encodeInTLVFromBuffer(r.Int,new Uint8Array(o));break}case n.PublishKey:t.encodeInTLVFromBuffer(r.Bytes,new Uint8Array).encodeInTLVFromBuffer(r.Bytes,new Uint8Array).encodeInTLVFromBuffer(r.PublicKey,e.recipient).encodeInTLVFromBuffer(r.PublicKey,new Uint8Array);break;case n.Derive:t.encodeInTLVFromBuffer(r.Bytes,u(e.path));break}const i=t.build();return new Uint8Array([e.type,i.length,...i])}toString(){return y(this.bytes,!1)}toU8A(){return this.bytes}parse(){return this.data.orDefaultLazy(()=>{const e=new l(this.bytes).parseCommandData();return this.data=c(e),e})}toHuman(){return this.parse().map(e=>Object.entries(e).map(([t,i])=>t==="type"?`${n[i]}(0x${i?.toString(16).padStart(2,"0")}):`:` ${t}: ${i instanceof Uint8Array?y(i,!1):i}`).join(`
|
|
2
|
+
`))}getPublicKey(){switch(this.bytes[0]){case n.AddMember:case n.PublishKey:return this.parse().toMaybe().chain(e=>{switch(e.type){case n.AddMember:return c(e.publicKey);case n.PublishKey:return c(e.recipient);default:return s}}).map(e=>y(e,!1));default:return s}}getEncryptedPublishedKey(){switch(this.bytes[0]){case n.Seed:case n.Derive:case n.PublishKey:return this.parse().toMaybe().chain(e=>{switch(e.type){case n.Seed:case n.Derive:case n.PublishKey:return p.of({...e});default:return s}});default:return s}}}export{m as LKRPCommand};
|
|
3
3
|
//# sourceMappingURL=LKRPCommand.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/utils/LKRPCommand.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n bufferToHexaString,\n ByteArrayBuilder,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Just, Maybe, Nothing, Right } from \"purify-ts\";\n\nimport { type LKRPParsingError } from \"@api/model/Errors\";\nimport {\n type LKRPCommandData,\n type UnsignedCommandData,\n} from \"@internal/models/LKRPCommandTypes\";\nimport { CommandTags, GeneralTags } from \"@internal/models/Tags\";\nimport { type EncryptedPublishedKey } from \"@internal/models/Types\";\n\nimport { derivationPathAsBytes } from \"./derivationPath\";\nimport { TLVParser } from \"./TLVParser\";\n\nexport class LKRPCommand {\n private data: Maybe<Either<LKRPParsingError, LKRPCommandData>>;\n\n constructor(\n private bytes: Uint8Array,\n data?: LKRPCommandData,\n ) {\n this.data = data ? Just(Right(data)) : Nothing;\n }\n\n static fromHex(hex: string): LKRPCommand {\n return new LKRPCommand(hexaStringToBuffer(hex) ?? new Uint8Array());\n }\n\n static fromData(data: LKRPCommandData): LKRPCommand {\n const tlv = new ByteArrayBuilder();\n switch (data.type) {\n case CommandTags.Seed:\n tlv\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.topic)\n .encodeInTLVFromUInt16(GeneralTags.Int, data.protocolVersion)\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.groupKey)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.initializationVector)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.encryptedXpriv)\n .encodeInTLVFromBuffer(\n GeneralTags.PublicKey,\n data.ephemeralPublicKey,\n );\n break;\n\n case CommandTags.AddMember
|
|
5
|
-
"mappings": "AAAA,OACE,sBAAAA,EACA,oBAAAC,EACA,sBAAAC,MACK,kCACP,OAAsB,QAAAC,EAAM,SAAAC,EAAO,WAAAC,EAAS,SAAAC,MAAa,YAOzD,OAAS,eAAAC,EAAa,eAAAC,MAAmB,wBAGzC,OAAS,yBAAAC,MAA6B,mBACtC,OAAS,aAAAC,MAAiB,cAEnB,MAAMC,CAAY,CAGvB,YACUC,EACRC,EACA,CAFQ,WAAAD,EAGR,KAAK,KAAOC,EAAOV,EAAKG,EAAMO,CAAI,CAAC,EAAIR,CACzC,CAPQ,KASR,OAAO,QAAQS,EAA0B,CACvC,OAAO,IAAIH,EAAYT,EAAmBY,CAAG,GAAK,IAAI,UAAY,CACpE,CAEA,OAAO,SAASD,EAAoC,CAClD,MAAME,EAAM,IAAId,EAChB,OAAQY,EAAK,KAAM,CACjB,KAAKN,EAAY,KACfQ,EACG,sBAAsBP,EAAY,MAAOK,EAAK,KAAK,EACnD,sBAAsBL,EAAY,IAAKK,EAAK,eAAe,EAC3D,sBAAsBL,EAAY,UAAWK,EAAK,QAAQ,EAC1D,sBAAsBL,EAAY,MAAOK,EAAK,oBAAoB,EAClE,sBAAsBL,EAAY,MAAOK,EAAK,cAAc,EAC5D,sBACCL,EAAY,UACZK,EAAK,kBACP,EACF,MAEF,KAAKN,EAAY,
|
|
6
|
-
"names": ["bufferToHexaString", "ByteArrayBuilder", "hexaStringToBuffer", "Just", "Maybe", "Nothing", "Right", "CommandTags", "GeneralTags", "derivationPathAsBytes", "TLVParser", "LKRPCommand", "bytes", "data", "hex", "tlv", "key", "value", "str"]
|
|
4
|
+
"sourcesContent": ["import {\n bufferToHexaString,\n ByteArrayBuilder,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Just, Maybe, Nothing, Right } from \"purify-ts\";\n\nimport { type LKRPParsingError } from \"@api/model/Errors\";\nimport {\n type LKRPCommandData,\n type UnsignedCommandData,\n} from \"@internal/models/LKRPCommandTypes\";\nimport { CommandTags, GeneralTags } from \"@internal/models/Tags\";\nimport { type EncryptedPublishedKey } from \"@internal/models/Types\";\n\nimport { derivationPathAsBytes } from \"./derivationPath\";\nimport { TLVParser } from \"./TLVParser\";\n\nexport class LKRPCommand {\n private data: Maybe<Either<LKRPParsingError, LKRPCommandData>>;\n\n constructor(\n private bytes: Uint8Array,\n data?: LKRPCommandData,\n ) {\n this.data = data ? Just(Right(data)) : Nothing;\n }\n\n static fromHex(hex: string): LKRPCommand {\n return new LKRPCommand(hexaStringToBuffer(hex) ?? new Uint8Array());\n }\n\n static fromData(data: LKRPCommandData): LKRPCommand {\n const tlv = new ByteArrayBuilder();\n switch (data.type) {\n case CommandTags.Seed:\n tlv\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.topic)\n .encodeInTLVFromUInt16(GeneralTags.Int, data.protocolVersion)\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.groupKey)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.initializationVector)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.encryptedXpriv)\n .encodeInTLVFromBuffer(\n GeneralTags.PublicKey,\n data.ephemeralPublicKey,\n );\n break;\n\n case CommandTags.AddMember: {\n const permissions = new ArrayBuffer(4);\n new DataView(permissions).setUint32(0, data.permissions);\n tlv\n .encodeInTLVFromAscii(GeneralTags.String, data.name)\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.publicKey)\n .encodeInTLVFromBuffer(GeneralTags.Int, new Uint8Array(permissions));\n break;\n }\n\n case CommandTags.PublishKey:\n tlv\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.initializationVector)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.encryptedXpriv)\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.recipient)\n .encodeInTLVFromBuffer(\n GeneralTags.PublicKey,\n data.ephemeralPublicKey,\n );\n break;\n\n case CommandTags.Derive:\n tlv\n .encodeInTLVFromBuffer(\n GeneralTags.Bytes,\n derivationPathAsBytes(data.path),\n )\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.groupKey)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.initializationVector)\n .encodeInTLVFromBuffer(GeneralTags.Bytes, data.encryptedXpriv)\n .encodeInTLVFromBuffer(\n GeneralTags.PublicKey,\n data.ephemeralPublicKey,\n );\n break;\n }\n\n const bytes = tlv.build();\n return new LKRPCommand(\n new Uint8Array([data.type, bytes.length, ...bytes]),\n data,\n );\n }\n\n static bytesFromUnsignedData(data: UnsignedCommandData): Uint8Array {\n const tlv = new ByteArrayBuilder();\n switch (data.type) {\n case CommandTags.AddMember: {\n // NOTE: encode the permission bytes array with DataView because\n // ByteArrayBuilder.encodeInTLVFromUInt32 doesn't seem to work with negative numbers\n // ByteArrayBuilder.add32BitIntToData doesn't seem to work with number > 0x7fffffff\n const permissions = new ArrayBuffer(4);\n new DataView(permissions).setUint32(0, data.permissions);\n tlv\n .encodeInTLVFromAscii(GeneralTags.String, data.name)\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.publicKey)\n .encodeInTLVFromBuffer(GeneralTags.Int, new Uint8Array(permissions));\n break;\n }\n\n case CommandTags.PublishKey:\n tlv\n .encodeInTLVFromBuffer(GeneralTags.Bytes, new Uint8Array()) // Empty IV\n .encodeInTLVFromBuffer(GeneralTags.Bytes, new Uint8Array()) // Empty encryptedXpriv\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, data.recipient)\n .encodeInTLVFromBuffer(GeneralTags.PublicKey, new Uint8Array()); // Empty ephemeralPublicKey\n break;\n\n case CommandTags.Derive:\n tlv.encodeInTLVFromBuffer(\n GeneralTags.Bytes,\n derivationPathAsBytes(data.path),\n );\n break;\n }\n\n const bytes = tlv.build();\n return new Uint8Array([data.type, bytes.length, ...bytes]);\n }\n\n toString(): string {\n return bufferToHexaString(this.bytes, false);\n }\n\n toU8A(): Uint8Array {\n return this.bytes;\n }\n\n parse(): Either<LKRPParsingError, LKRPCommandData> {\n return this.data.orDefaultLazy(() => {\n const data = new TLVParser(this.bytes).parseCommandData();\n this.data = Just(data);\n return data;\n });\n }\n\n toHuman(): Either<LKRPParsingError, string> {\n return this.parse().map((data) =>\n Object.entries(data)\n .map(([key, value]) => {\n if (key === \"type\") {\n return `${CommandTags[value as CommandTags]}(0x${value?.toString(16).padStart(2, \"0\")}):`;\n }\n return ` ${key}: ${value instanceof Uint8Array ? bufferToHexaString(value, false) : value}`;\n })\n .join(\"\\n\"),\n );\n }\n\n getPublicKey(): Maybe<string> {\n switch (this.bytes[0]) {\n case CommandTags.AddMember:\n case CommandTags.PublishKey:\n return this.parse()\n .toMaybe()\n .chain((data) => {\n switch (data.type) {\n case CommandTags.AddMember:\n return Just(data.publicKey);\n case CommandTags.PublishKey:\n return Just(data.recipient);\n default:\n return Nothing;\n }\n })\n .map((str) => bufferToHexaString(str, false));\n\n default:\n return Nothing;\n }\n }\n\n getEncryptedPublishedKey(): Maybe<EncryptedPublishedKey> {\n switch (this.bytes[0]) {\n case CommandTags.Seed:\n case CommandTags.Derive:\n case CommandTags.PublishKey:\n return this.parse()\n .toMaybe()\n .chain((data) => {\n switch (data.type) {\n case CommandTags.Seed:\n case CommandTags.Derive:\n case CommandTags.PublishKey:\n return Maybe.of({ ...data });\n default:\n return Nothing;\n }\n });\n default:\n return Nothing;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OACE,sBAAAA,EACA,oBAAAC,EACA,sBAAAC,MACK,kCACP,OAAsB,QAAAC,EAAM,SAAAC,EAAO,WAAAC,EAAS,SAAAC,MAAa,YAOzD,OAAS,eAAAC,EAAa,eAAAC,MAAmB,wBAGzC,OAAS,yBAAAC,MAA6B,mBACtC,OAAS,aAAAC,MAAiB,cAEnB,MAAMC,CAAY,CAGvB,YACUC,EACRC,EACA,CAFQ,WAAAD,EAGR,KAAK,KAAOC,EAAOV,EAAKG,EAAMO,CAAI,CAAC,EAAIR,CACzC,CAPQ,KASR,OAAO,QAAQS,EAA0B,CACvC,OAAO,IAAIH,EAAYT,EAAmBY,CAAG,GAAK,IAAI,UAAY,CACpE,CAEA,OAAO,SAASD,EAAoC,CAClD,MAAME,EAAM,IAAId,EAChB,OAAQY,EAAK,KAAM,CACjB,KAAKN,EAAY,KACfQ,EACG,sBAAsBP,EAAY,MAAOK,EAAK,KAAK,EACnD,sBAAsBL,EAAY,IAAKK,EAAK,eAAe,EAC3D,sBAAsBL,EAAY,UAAWK,EAAK,QAAQ,EAC1D,sBAAsBL,EAAY,MAAOK,EAAK,oBAAoB,EAClE,sBAAsBL,EAAY,MAAOK,EAAK,cAAc,EAC5D,sBACCL,EAAY,UACZK,EAAK,kBACP,EACF,MAEF,KAAKN,EAAY,UAAW,CAC1B,MAAMS,EAAc,IAAI,YAAY,CAAC,EACrC,IAAI,SAASA,CAAW,EAAE,UAAU,EAAGH,EAAK,WAAW,EACvDE,EACG,qBAAqBP,EAAY,OAAQK,EAAK,IAAI,EAClD,sBAAsBL,EAAY,UAAWK,EAAK,SAAS,EAC3D,sBAAsBL,EAAY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ACf,OAAO,KAAK,MAAM,EACf,QAAQ,EACR,MAAOM,GAAS,CACf,OAAQA,EAAK,KAAM,CACjB,KAAKN,EAAY,KACjB,KAAKA,EAAY,OACjB,KAAKA,EAAY,WACf,OAAOH,EAAM,GAAG,CAAE,GAAGS,CAAK,CAAC,EAC7B,QACE,OAAOR,CACX,CACF,CAAC,EACL,QACE,OAAOA,CACX,CACF,CACF",
|
|
6
|
+
"names": ["bufferToHexaString", "ByteArrayBuilder", "hexaStringToBuffer", "Just", "Maybe", "Nothing", "Right", "CommandTags", "GeneralTags", "derivationPathAsBytes", "TLVParser", "LKRPCommand", "bytes", "data", "hex", "tlv", "permissions", "key", "value", "str"]
|
|
7
7
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{Just as
|
|
2
|
-
`)))}),it("should fail for invalid command bytes format",()=>{const
|
|
1
|
+
import{Just as a,Left as d,Nothing as m,Right as f}from"purify-ts";import{LKRPParsingError as s}from"../../api/model/Errors";import{Permissions as c}from"../../api/model/Permissions";import{CommandTags as r,GeneralTags as e}from"../models/Tags";import{LKRPCommand as n}from"./LKRPCommand";describe("LKRPCommand",()=>{describe("fromData",()=>{it("should encode add member permissions correctly",()=>{const x=Uint8Array.from([2,191,92,13,155,240,244,149,22,40,90,210,3,146,196,196,184,113,20,246,196,140,132,115,6,222,31,231,243,147,78,67,193]),t=n.fromData({type:r.AddMember,name:"OWNER",publicKey:x,permissions:c.OWNER}),o=n.fromData({type:r.AddMember,name:"READER",publicKey:x,permissions:c.CAN_ENCRYPT}),i=n.fromData({type:r.AddMember,name:"DAPP",publicKey:x,permissions:c.OWNER&~c.CAN_ADD_BLOCK});expect(t.toString()).toBe(["11 30","04 05 4f 57 4e 45 52","06 21 02 bf 5c 0d 9b f0 f4 95 16 28 5a d2 03 92 c4 c4 b8 71 14 f6 c4 8c 84 73 06 de 1f e7 f3 93 4e 43 c1","01 04 ff ff ff ff"].join("").replace(/ /g,"")),expect(o.toString()).toBe(["11 31","04 06 52 45 41 44 45 52","06 21 02 bf 5c 0d 9b f0 f4 95 16 28 5a d2 03 92 c4 c4 b8 71 14 f6 c4 8c 84 73 06 de 1f e7 f3 93 4e 43 c1","01 04 00 00 00 01"].join("").replace(/ /g,"")),expect(i.toString()).toBe(["11 2f","04 04 44 41 50 50","06 21 02 bf 5c 0d 9b f0 f4 95 16 28 5a d2 03 92 c4 c4 b8 71 14 f6 c4 8c 84 73 06 de 1f e7 f3 93 4e 43 c1","01 04 ff ff ff fb"].join("").replace(/ /g,""))})}),describe("bytesFromUnsignedData",()=>{it("should encode add member permissions correctly",()=>{const x=Uint8Array.from([2,191,92,13,155,240,244,149,22,40,90,210,3,146,196,196,184,113,20,246,196,140,132,115,6,222,31,231,243,147,78,67,193]),t=n.bytesFromUnsignedData({type:r.AddMember,name:"OWNER",publicKey:x,permissions:c.OWNER}),o=n.bytesFromUnsignedData({type:r.AddMember,name:"READER",publicKey:x,permissions:c.CAN_ENCRYPT}),i=n.bytesFromUnsignedData({type:r.AddMember,name:"DAPP",publicKey:x,permissions:c.OWNER&~c.CAN_ADD_BLOCK});expect(t).toEqual(Uint8Array.from([[17,48],[4,5,79,87,78,69,82],[6,33,2,191,92,13,155,240,244,149,22,40,90,210,3,146,196,196,184,113,20,246,196,140,132,115,6,222,31,231,243,147,78,67,193],[1,4,255,255,255,255]].flat())),expect(o).toEqual(Uint8Array.from([[17,49],[4,6,82,69,65,68,69,82],[6,33,2,191,92,13,155,240,244,149,22,40,90,210,3,146,196,196,184,113,20,246,196,140,132,115,6,222,31,231,243,147,78,67,193],[1,4,0,0,0,1]].flat())),expect(i).toEqual(Uint8Array.from([[17,47],[4,4,68,65,80,80],[6,33,2,191,92,13,155,240,244,149,22,40,90,210,3,146,196,196,184,113,20,246,196,140,132,115,6,222,31,231,243,147,78,67,193],[1,4,255,255,255,251]].flat()))})}),describe("toString",()=>{it("should return the hex of the bytes of the command",()=>{const x="0102030405060708",t=n.fromHex(x);expect(t.toString()).toBe(x)})}),describe("toU8A",()=>{it("should return the bytes of the command",()=>{const x=new Uint8Array([1,2,3,4,5,6,7,8]),t=new n(x);expect(t.toU8A()).toBe(x)})}),describe("parse",()=>{it("should parse the command data correctly",()=>{const x=new Uint8Array([e.Bytes,3,1,2,3,e.Int,2,1,2,e.PublicKey,3,2,4,6,e.Bytes,3,3,5,7,e.Bytes,3,4,8,16,e.PublicKey,3,10,11,12]),t=new n(new Uint8Array([r.Seed,x.length,...x]));expect(t.parse()).toStrictEqual(f({type:r.Seed,topic:new Uint8Array([1,2,3]),protocolVersion:258,groupKey:new Uint8Array([2,4,6]),initializationVector:new Uint8Array([3,5,7]),encryptedXpriv:new Uint8Array([4,8,16]),ephemeralPublicKey:new Uint8Array([10,11,12])}))}),it("should fail with invalid command bytes",()=>{const x=new n(new Uint8Array([r.Seed,1,1]));expect(x.parse()).toStrictEqual(d(new s("Invalid end of TLV, expected length")))})}),describe("getPublicKey",()=>{it("should return the public key for AddMember command",()=>{const x=new Uint8Array([e.String,3,65,66,67,e.PublicKey,3,4,5,6,e.Int,1,1]),t=new n(new Uint8Array([r.AddMember,x.length,...x]));expect(t.getPublicKey()).toStrictEqual(a("040506"))}),it("should return the public key for PublishKey commands",()=>{const x=new Uint8Array([e.Bytes,3,1,2,3,e.Bytes,3,4,5,6,e.PublicKey,3,7,8,9,e.PublicKey,3,10,11,12]),t=new n(new Uint8Array([r.PublishKey,x.length,...x]));expect(t.getPublicKey()).toEqual(a("070809"))}),it("should return undefined for other command types",()=>{const x=new n(new Uint8Array([r.Seed]));expect(x.getPublicKey()).toEqual(m)})}),describe("toHuman",()=>{it("should return a string representation of the command",()=>{const x=new Uint8Array([e.Bytes,3,1,2,3,e.Bytes,3,4,5,6,e.PublicKey,3,7,8,9,e.PublicKey,3,10,11,12]),t=new n(new Uint8Array([r.PublishKey,x.length,...x]));expect(t.toHuman()).toStrictEqual(f(["PublishKey(0x12):"," initializationVector: 010203"," encryptedXpriv: 040506"," recipient: 070809"," ephemeralPublicKey: 0a0b0c"].join(`
|
|
2
|
+
`)))}),it("should fail for invalid command bytes format",()=>{const x=new n(new Uint8Array([r.Seed,1,1]));expect(x.toHuman()).toStrictEqual(d(new s("Invalid end of TLV, expected length")))})})});
|
|
3
3
|
//# sourceMappingURL=LKRPCommand.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/utils/LKRPCommand.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { Just, Left, Nothing, Right } from \"purify-ts\";\n\nimport { LKRPParsingError } from \"@api/model/Errors\";\nimport { CommandTags, GeneralTags } from \"@internal/models/Tags\";\n\nimport { LKRPCommand } from \"./LKRPCommand\";\n\ndescribe(\"LKRPCommand\", () => {\n describe(\"toString\", () => {\n it(\"should return the hex of the bytes of the command\", () => {\n // WHEN\n const hex = \"0102030405060708\";\n const command = LKRPCommand.fromHex(hex);\n // THEN\n expect(command.toString()).toBe(hex);\n });\n });\n\n describe(\"toU8A\", () => {\n it(\"should return the bytes of the command\", () => {\n // WHEN\n const bytes = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);\n const command = new LKRPCommand(bytes);\n // THEN\n expect(command.toU8A()).toBe(bytes);\n });\n });\n\n describe(\"parse\", () => {\n it(\"should parse the command data correctly\", () => {\n // GIVEN\n const value = new Uint8Array([\n ...[GeneralTags.Bytes, 3, 0x01, 0x02, 0x03], // Topic\n ...[GeneralTags.Int, 2, 0x01, 0x02], // Protocol Version\n ...[GeneralTags.PublicKey, 3, 0x02, 0x04, 0x06], // Group Key\n ...[GeneralTags.Bytes, 3, 0x03, 0x05, 0x07], // Initialization Vector\n ...[GeneralTags.Bytes, 3, 0x04, 0x08, 0x10], // Encrypted xpriv\n ...[GeneralTags.PublicKey, 3, 0x0a, 0x0b, 0x0c], // Ephemeral Public Key\n ]);\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.Seed, value.length, ...value]),\n );\n // THEN\n expect(command.parse()).toStrictEqual(\n Right({\n type: CommandTags.Seed,\n topic: new Uint8Array([0x01, 0x02, 0x03]),\n protocolVersion: 258,\n groupKey: new Uint8Array([0x02, 0x04, 0x06]),\n initializationVector: new Uint8Array([0x03, 0x05, 0x07]),\n encryptedXpriv: new Uint8Array([0x04, 0x08, 0x10]),\n ephemeralPublicKey: new Uint8Array([0x0a, 0x0b, 0x0c]),\n }),\n );\n });\n\n it(\"should fail with invalid command bytes\", () => {\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.Seed, 1, ...[0x01]]),\n );\n // THEN\n expect(command.parse()).toStrictEqual(\n Left(new LKRPParsingError(\"Invalid end of TLV, expected length\")),\n );\n });\n });\n\n describe(\"getPublicKey\", () => {\n it(\"should return the public key for AddMember command\", () => {\n // GIVEN\n const addMemberValue = new Uint8Array([\n ...[GeneralTags.String, 3, 0x41, 0x42, 0x43], // Name \"ABC\"\n ...[GeneralTags.PublicKey, 3, 0x04, 0x05, 0x06], // Public Key\n ...[GeneralTags.Int, 1, 0x01], // Permissions\n ]);\n\n // WHEN\n const addMemberCmd = new LKRPCommand(\n new Uint8Array([\n CommandTags.AddMember,\n addMemberValue.length,\n ...addMemberValue,\n ]),\n );\n\n // THEN\n expect(addMemberCmd.getPublicKey()).toStrictEqual(Just(\"040506\"));\n });\n\n it(\"should return the public key for PublishKey commands\", () => {\n // GIVEN\n const publishKeyValue = new Uint8Array([\n ...[GeneralTags.Bytes, 3, 0x01, 0x02, 0x03], // Initialization Vector\n ...[GeneralTags.Bytes, 3, 0x04, 0x05, 0x06], // Encrypted xpriv\n ...[GeneralTags.PublicKey, 3, 0x07, 0x08, 0x09], // Recipient\n ...[GeneralTags.PublicKey, 3, 0x0a, 0x0b, 0x0c], // Ephemeral Public Key\n ]);\n // WHEN\n const publishKeyCmd = new LKRPCommand(\n new Uint8Array([\n CommandTags.PublishKey,\n publishKeyValue.length,\n ...publishKeyValue,\n ]),\n );\n // THEN\n expect(publishKeyCmd.getPublicKey()).toEqual(Just(\"070809\"));\n });\n\n it(\"should return undefined for other command types\", () => {\n // WHEN\n const command = new LKRPCommand(new Uint8Array([CommandTags.Seed]));\n // THEN\n expect(command.getPublicKey()).toEqual(Nothing);\n });\n });\n\n describe(\"toHuman\", () => {\n it(\"should return a string representation of the command\", () => {\n // GIVEN\n const value = new Uint8Array([\n ...[GeneralTags.Bytes, 3, 0x01, 0x02, 0x03], // Initialization Vector\n ...[GeneralTags.Bytes, 3, 0x04, 0x05, 0x06], // Encrypted xpriv\n ...[GeneralTags.PublicKey, 3, 0x07, 0x08, 0x09], // Recipient\n ...[GeneralTags.PublicKey, 3, 0x0a, 0x0b, 0x0c], // Ephemeral Public Key\n ]);\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.PublishKey, value.length, ...value]),\n );\n // THEN\n expect(command.toHuman()).toStrictEqual(\n Right(\n [\n `PublishKey(0x12):`,\n ` initializationVector: 010203`,\n ` encryptedXpriv: 040506`,\n ` recipient: 070809`,\n ` ephemeralPublicKey: 0a0b0c`,\n ].join(\"\\n\"),\n ),\n );\n });\n\n it(\"should fail for invalid command bytes format\", () => {\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.Seed, 1, ...[0x01]]),\n );\n // THEN\n expect(command.toHuman()).toStrictEqual(\n Left(new LKRPParsingError(\"Invalid end of TLV, expected length\")),\n );\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,QAAAC,EAAM,WAAAC,EAAS,SAAAC,MAAa,YAE3C,OAAS,oBAAAC,MAAwB,oBACjC,OAAS,eAAAC,EAAa,eAAAC,MAAmB,wBAEzC,OAAS,eAAAC,MAAmB,gBAE5B,SAAS,cAAe,IAAM,CAC5B,SAAS,WAAY,IAAM,CACzB,GAAG,oDAAqD,IAAM,CAE5D,MAAMC,EAAM,mBACNC,
|
|
6
|
-
"names": ["Just", "Left", "Nothing", "Right", "LKRPParsingError", "CommandTags", "GeneralTags", "LKRPCommand", "hex", "command", "bytes", "value", "addMemberValue", "addMemberCmd", "publishKeyValue", "publishKeyCmd"]
|
|
4
|
+
"sourcesContent": ["import { Just, Left, Nothing, Right } from \"purify-ts\";\n\nimport { LKRPParsingError } from \"@api/model/Errors\";\nimport { Permissions } from \"@api/model/Permissions\";\nimport { CommandTags, GeneralTags } from \"@internal/models/Tags\";\n\nimport { LKRPCommand } from \"./LKRPCommand\";\n\ndescribe(\"LKRPCommand\", () => {\n describe(\"fromData\", () => {\n it(\"should encode add member permissions correctly\", () => {\n // GIVEN\n const publicKey = Uint8Array.from([\n 0x02, 0xbf, 0x5c, 0x0d, 0x9b, 0xf0, 0xf4, 0x95, 0x16, 0x28, 0x5a, 0xd2,\n 0x03, 0x92, 0xc4, 0xc4, 0xb8, 0x71, 0x14, 0xf6, 0xc4, 0x8c, 0x84, 0x73,\n 0x06, 0xde, 0x1f, 0xe7, 0xf3, 0x93, 0x4e, 0x43, 0xc1,\n ]);\n // WHEN\n const addOwner = LKRPCommand.fromData({\n type: CommandTags.AddMember,\n name: \"OWNER\",\n publicKey,\n permissions: Permissions.OWNER,\n });\n const addReader = LKRPCommand.fromData({\n type: CommandTags.AddMember,\n name: \"READER\",\n publicKey,\n permissions: Permissions.CAN_ENCRYPT,\n });\n const dapp = LKRPCommand.fromData({\n type: CommandTags.AddMember,\n name: \"DAPP\",\n publicKey,\n permissions: Permissions.OWNER & ~Permissions.CAN_ADD_BLOCK,\n });\n // THEN\n expect(addOwner.toString()).toBe(\n [\n \"11 30\", // header\n \"04 05 4f 57 4e 45 52\", // name\n \"06 21 02 bf 5c 0d 9b f0 f4 95 16 28 5a d2 03 92 c4 c4 b8 71 14 f6 c4 8c 84 73 06 de 1f e7 f3 93 4e 43 c1\", // public key\n \"01 04 ff ff ff ff\", // permissions (OWNER)\n ]\n .join(\"\")\n .replace(/ /g, \"\"),\n );\n expect(addReader.toString()).toBe(\n [\n \"11 31\", // header\n \"04 06 52 45 41 44 45 52\", // name\n \"06 21 02 bf 5c 0d 9b f0 f4 95 16 28 5a d2 03 92 c4 c4 b8 71 14 f6 c4 8c 84 73 06 de 1f e7 f3 93 4e 43 c1\", // public key\n \"01 04 00 00 00 01\", // permissions (CAN_ENCRYPT)\n ]\n .join(\"\")\n .replace(/ /g, \"\"),\n );\n expect(dapp.toString()).toBe(\n [\n \"11 2f\", // header\n \"04 04 44 41 50 50\", // name\n \"06 21 02 bf 5c 0d 9b f0 f4 95 16 28 5a d2 03 92 c4 c4 b8 71 14 f6 c4 8c 84 73 06 de 1f e7 f3 93 4e 43 c1\", // public key\n \"01 04 ff ff ff fb\", // permissions (OWNER & ~CAN_ADD_BLOCK)\n ]\n .join(\"\")\n .replace(/ /g, \"\"),\n );\n });\n });\n\n describe(\"bytesFromUnsignedData\", () => {\n it(\"should encode add member permissions correctly\", () => {\n // GIVEN\n const publicKey = Uint8Array.from([\n 0x02, 0xbf, 0x5c, 0x0d, 0x9b, 0xf0, 0xf4, 0x95, 0x16, 0x28, 0x5a, 0xd2,\n 0x03, 0x92, 0xc4, 0xc4, 0xb8, 0x71, 0x14, 0xf6, 0xc4, 0x8c, 0x84, 0x73,\n 0x06, 0xde, 0x1f, 0xe7, 0xf3, 0x93, 0x4e, 0x43, 0xc1,\n ]);\n // WHEN\n const addOwner = LKRPCommand.bytesFromUnsignedData({\n type: CommandTags.AddMember,\n name: \"OWNER\",\n publicKey,\n permissions: Permissions.OWNER,\n });\n const addReader = LKRPCommand.bytesFromUnsignedData({\n type: CommandTags.AddMember,\n name: \"READER\",\n publicKey,\n permissions: Permissions.CAN_ENCRYPT,\n });\n const dapp = LKRPCommand.bytesFromUnsignedData({\n type: CommandTags.AddMember,\n name: \"DAPP\",\n publicKey,\n permissions: Permissions.OWNER & ~Permissions.CAN_ADD_BLOCK,\n });\n // THEN\n expect(addOwner).toEqual(\n Uint8Array.from(\n [\n [0x11, 0x30], // header\n [0x04, 0x05, 0x4f, 0x57, 0x4e, 0x45, 0x52], // name\n [\n // public key\n 0x06, 0x21, 0x02, 0xbf, 0x5c, 0x0d, 0x9b, 0xf0, 0xf4, 0x95, 0x16,\n 0x28, 0x5a, 0xd2, 0x03, 0x92, 0xc4, 0xc4, 0xb8, 0x71, 0x14, 0xf6,\n 0xc4, 0x8c, 0x84, 0x73, 0x06, 0xde, 0x1f, 0xe7, 0xf3, 0x93, 0x4e,\n 0x43, 0xc1,\n ],\n [0x01, 0x04, 0xff, 0xff, 0xff, 0xff], // permissions (OWNER)\n ].flat(),\n ),\n );\n expect(addReader).toEqual(\n Uint8Array.from(\n [\n [0x11, 0x31], // header\n [0x04, 0x06, 0x52, 0x45, 0x41, 0x44, 0x45, 0x52], // name\n [\n // public key\n 0x06, 0x21, 0x02, 0xbf, 0x5c, 0x0d, 0x9b, 0xf0, 0xf4, 0x95, 0x16,\n 0x28, 0x5a, 0xd2, 0x03, 0x92, 0xc4, 0xc4, 0xb8, 0x71, 0x14, 0xf6,\n 0xc4, 0x8c, 0x84, 0x73, 0x06, 0xde, 0x1f, 0xe7, 0xf3, 0x93, 0x4e,\n 0x43, 0xc1,\n ],\n [0x01, 0x04, 0x00, 0x00, 0x00, 0x01], // permissions (CAN_ENCRYPT)\n ].flat(),\n ),\n );\n expect(dapp).toEqual(\n Uint8Array.from(\n [\n [0x11, 0x2f], // header\n [0x04, 0x04, 0x44, 0x41, 0x50, 0x50], // name\n [\n // public key\n 0x06, 0x21, 0x02, 0xbf, 0x5c, 0x0d, 0x9b, 0xf0, 0xf4, 0x95, 0x16,\n 0x28, 0x5a, 0xd2, 0x03, 0x92, 0xc4, 0xc4, 0xb8, 0x71, 0x14, 0xf6,\n 0xc4, 0x8c, 0x84, 0x73, 0x06, 0xde, 0x1f, 0xe7, 0xf3, 0x93, 0x4e,\n 0x43, 0xc1,\n ],\n [0x01, 0x04, 0xff, 0xff, 0xff, 0xfb], // permissions (OWNER & ~CAN_ADD_BLOCK)\n ].flat(),\n ),\n );\n });\n });\n\n describe(\"toString\", () => {\n it(\"should return the hex of the bytes of the command\", () => {\n // WHEN\n const hex = \"0102030405060708\";\n const command = LKRPCommand.fromHex(hex);\n // THEN\n expect(command.toString()).toBe(hex);\n });\n });\n\n describe(\"toU8A\", () => {\n it(\"should return the bytes of the command\", () => {\n // WHEN\n const bytes = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);\n const command = new LKRPCommand(bytes);\n // THEN\n expect(command.toU8A()).toBe(bytes);\n });\n });\n\n describe(\"parse\", () => {\n it(\"should parse the command data correctly\", () => {\n // GIVEN\n const value = new Uint8Array([\n ...[GeneralTags.Bytes, 3, 0x01, 0x02, 0x03], // Topic\n ...[GeneralTags.Int, 2, 0x01, 0x02], // Protocol Version\n ...[GeneralTags.PublicKey, 3, 0x02, 0x04, 0x06], // Group Key\n ...[GeneralTags.Bytes, 3, 0x03, 0x05, 0x07], // Initialization Vector\n ...[GeneralTags.Bytes, 3, 0x04, 0x08, 0x10], // Encrypted xpriv\n ...[GeneralTags.PublicKey, 3, 0x0a, 0x0b, 0x0c], // Ephemeral Public Key\n ]);\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.Seed, value.length, ...value]),\n );\n // THEN\n expect(command.parse()).toStrictEqual(\n Right({\n type: CommandTags.Seed,\n topic: new Uint8Array([0x01, 0x02, 0x03]),\n protocolVersion: 258,\n groupKey: new Uint8Array([0x02, 0x04, 0x06]),\n initializationVector: new Uint8Array([0x03, 0x05, 0x07]),\n encryptedXpriv: new Uint8Array([0x04, 0x08, 0x10]),\n ephemeralPublicKey: new Uint8Array([0x0a, 0x0b, 0x0c]),\n }),\n );\n });\n\n it(\"should fail with invalid command bytes\", () => {\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.Seed, 1, ...[0x01]]),\n );\n // THEN\n expect(command.parse()).toStrictEqual(\n Left(new LKRPParsingError(\"Invalid end of TLV, expected length\")),\n );\n });\n });\n\n describe(\"getPublicKey\", () => {\n it(\"should return the public key for AddMember command\", () => {\n // GIVEN\n const addMemberValue = new Uint8Array([\n ...[GeneralTags.String, 3, 0x41, 0x42, 0x43], // Name \"ABC\"\n ...[GeneralTags.PublicKey, 3, 0x04, 0x05, 0x06], // Public Key\n ...[GeneralTags.Int, 1, 0x01], // Permissions\n ]);\n\n // WHEN\n const addMemberCmd = new LKRPCommand(\n new Uint8Array([\n CommandTags.AddMember,\n addMemberValue.length,\n ...addMemberValue,\n ]),\n );\n\n // THEN\n expect(addMemberCmd.getPublicKey()).toStrictEqual(Just(\"040506\"));\n });\n\n it(\"should return the public key for PublishKey commands\", () => {\n // GIVEN\n const publishKeyValue = new Uint8Array([\n ...[GeneralTags.Bytes, 3, 0x01, 0x02, 0x03], // Initialization Vector\n ...[GeneralTags.Bytes, 3, 0x04, 0x05, 0x06], // Encrypted xpriv\n ...[GeneralTags.PublicKey, 3, 0x07, 0x08, 0x09], // Recipient\n ...[GeneralTags.PublicKey, 3, 0x0a, 0x0b, 0x0c], // Ephemeral Public Key\n ]);\n // WHEN\n const publishKeyCmd = new LKRPCommand(\n new Uint8Array([\n CommandTags.PublishKey,\n publishKeyValue.length,\n ...publishKeyValue,\n ]),\n );\n // THEN\n expect(publishKeyCmd.getPublicKey()).toEqual(Just(\"070809\"));\n });\n\n it(\"should return undefined for other command types\", () => {\n // WHEN\n const command = new LKRPCommand(new Uint8Array([CommandTags.Seed]));\n // THEN\n expect(command.getPublicKey()).toEqual(Nothing);\n });\n });\n\n describe(\"toHuman\", () => {\n it(\"should return a string representation of the command\", () => {\n // GIVEN\n const value = new Uint8Array([\n ...[GeneralTags.Bytes, 3, 0x01, 0x02, 0x03], // Initialization Vector\n ...[GeneralTags.Bytes, 3, 0x04, 0x05, 0x06], // Encrypted xpriv\n ...[GeneralTags.PublicKey, 3, 0x07, 0x08, 0x09], // Recipient\n ...[GeneralTags.PublicKey, 3, 0x0a, 0x0b, 0x0c], // Ephemeral Public Key\n ]);\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.PublishKey, value.length, ...value]),\n );\n // THEN\n expect(command.toHuman()).toStrictEqual(\n Right(\n [\n `PublishKey(0x12):`,\n ` initializationVector: 010203`,\n ` encryptedXpriv: 040506`,\n ` recipient: 070809`,\n ` ephemeralPublicKey: 0a0b0c`,\n ].join(\"\\n\"),\n ),\n );\n });\n\n it(\"should fail for invalid command bytes format\", () => {\n // WHEN\n const command = new LKRPCommand(\n new Uint8Array([CommandTags.Seed, 1, ...[0x01]]),\n );\n // THEN\n expect(command.toHuman()).toStrictEqual(\n Left(new LKRPParsingError(\"Invalid end of TLV, expected length\")),\n );\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,QAAAC,EAAM,WAAAC,EAAS,SAAAC,MAAa,YAE3C,OAAS,oBAAAC,MAAwB,oBACjC,OAAS,eAAAC,MAAmB,yBAC5B,OAAS,eAAAC,EAAa,eAAAC,MAAmB,wBAEzC,OAAS,eAAAC,MAAmB,gBAE5B,SAAS,cAAe,IAAM,CAC5B,SAAS,WAAY,IAAM,CACzB,GAAG,iDAAkD,IAAM,CAEzD,MAAMC,EAAY,WAAW,KAAK,CAChC,EAAM,IAAM,GAAM,GAAM,IAAM,IAAM,IAAM,IAAM,GAAM,GAAM,GAAM,IAClE,EAAM,IAAM,IAAM,IAAM,IAAM,IAAM,GAAM,IAAM,IAAM,IAAM,IAAM,IAClE,EAAM,IAAM,GAAM,IAAM,IAAM,IAAM,GAAM,GAAM,GAClD,CAAC,EAEKC,EAAWF,EAAY,SAAS,CACpC,KAAMF,EAAY,UAClB,KAAM,QACN,UAAAG,EACA,YAAaJ,EAAY,KAC3B,CAAC,EACKM,EAAYH,EAAY,SAAS,CACrC,KAAMF,EAAY,UAClB,KAAM,SACN,UAAAG,EACA,YAAaJ,EAAY,WAC3B,CAAC,EACKO,EAAOJ,EAAY,SAAS,CAChC,KAAMF,EAAY,UAClB,KAAM,OACN,UAAAG,EACA,YAAaJ,EAAY,MAAQ,CAACA,EAAY,aAChD,CAAC,EAED,OAAOK,EAAS,SA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AAW,CAACF,EAAY,WAAYU,EAAM,OAAQ,GAAGA,CAAK,CAAC,CACjE,EAEA,OAAOF,EAAQ,QAAQ,CAAC,EAAE,cACxBX,EACE,CACE,oBACA,iCACA,2BACA,sBACA,8BACF,EAAE,KAAK;AAAA,CAAI,CACb,CACF,CACF,CAAC,EAED,GAAG,+CAAgD,IAAM,CAEvD,MAAMW,EAAU,IAAIN,EAClB,IAAI,WAAW,CAACF,EAAY,KAAM,EAAO,CAAK,CAAC,CACjD,EAEA,OAAOQ,EAAQ,QAAQ,CAAC,EAAE,cACxBb,EAAK,IAAIG,EAAiB,qCAAqC,CAAC,CAClE,CACF,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["Just", "Left", "Nothing", "Right", "LKRPParsingError", "Permissions", "CommandTags", "GeneralTags", "LKRPCommand", "publicKey", "addOwner", "addReader", "dapp", "hex", "command", "bytes", "value", "addMemberValue", "addMemberCmd", "publishKeyValue", "publishKeyCmd"]
|
|
7
7
|
}
|
package/lib/esm/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/device-trusted-app-kit-ledger-keyring-protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"exports": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@ledgerhq/device-management-kit": "workspace:*",
|
|
39
|
-
"@ledgerhq/signer-utils": "
|
|
39
|
+
"@ledgerhq/signer-utils": "^1.1.0",
|
|
40
40
|
"@noble/ciphers": "^1.3.0",
|
|
41
41
|
"@noble/curves": "^1.9.7",
|
|
42
42
|
"@noble/hashes": "^1.8.0",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LKRPCommand.d.ts","sourceRoot":"","sources":["../../../../src/internal/utils/LKRPCommand.ts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