entropyxyz / cli

CLI utility to ease interactions with an Entropy network.
GNU Affero General Public License v3.0
5 stars 0 forks source link

Config de/serialization #160

Open mixmix opened 3 days ago

mixmix commented 3 days ago

While looking at a logger PR I noticed there was some spaaam coming through, followed it upstream and discovered that our config serialization is a big janky... and likewise deserialization

Here's what a config looks like (safe to steal, this is a testing account):

{"accounts":[{"name":"Mix","address":"5DfWeADcWVtc4mwaV8EwKLgmNjyEDxpadNuTupq7an7xjSqk","data":{"debug":true,"seed":"0xdceffc4b8a2b99ea683ec8d3c72cc0822a49c859cffe897102cc4e4eee366480","admin":{"address":"5DfWeADcWVtc4mwaV8EwKLgmNjyEDxpadNuTupq7an7xjSqk","type":"registration","verifyingKeys":[],"userContext":"ADMIN_KEY","seed":"0xdceffc4b8a2b99ea683ec8d3c72cc0822a49c859cffe897102cc4e4eee366480","path":"","pair":{"address":"5DfWeADcWVtc4mwaV8EwKLgmNjyEDxpadNuTupq7an7xjSqk","addressRaw":{"0":70,"1":200,"2":17,"3":57,"4":167,"5":58,"6":228,"7":98,"8":184,"9":144,"10":52,"11":128,"12":63,"13":22,"14":82,"15":99,"16":21,"17":76,"18":38,"19":171,"20":24,"21":127,"22":177,"23":153,"24":145,"25":20,"26":61,"27":52,"28":82,"29":194,"30":223,"31":63},"isLocked":false,"meta":{},"publicKey":{"0":70,"1":200,"2":17,"3":57,"4":167,"5":58,"6":228,"7":98,"8":184,"9":144,"10":52,"11":128,"12":63,"13":22,"14":82,"15":99,"16":21,"17":76,"18":38,"19":171,"20":24,"21":127,"22":177,"23":153,"24":145,"25":20,"26":61,"27":52,"28":82,"29":194,"30":223,"31":63},"type":"sr25519","secretKey":{"0":24,"1":28,"2":142,"3":167,"4":100,"5":166,"6":225,"7":62,"8":152,"9":83,"10":129,"11":0,"12":153,"13":25,"14":162,"15":0,"16":255,"17":1,"18":75,"19":122,"20":215,"21":146,"22":125,"23":10,"24":76,"25":240,"26":180,"27":186,"28":112,"29":12,"30":191,"31":76,"32":136,"33":121,"34":125,"35":69,"36":2,"37":96,"38":175,"39":109,"40":81,"41":38,"42":218,"43":224,"44":117,"45":47,"46":228,"47":14,"48":246,"49":64,"50":240,"51":164,"52":207,"53":181,"54":250,"55":124,"56":252,"57":207,"58":176,"59":113,"60":226,"61":240,"62":247,"63":112}}},"registration":{"address":"5DfWeADcWVtc4mwaV8EwKLgmNjyEDxpadNuTupq7an7xjSqk","type":"registration","verifyingKeys":[],"userContext":"ADMIN_KEY","seed":"0xdceffc4b8a2b99ea683ec8d3c72cc0822a49c859cffe897102cc4e4eee366480","path":"","pair":{"address":"5DfWeADcWVtc4mwaV8EwKLgmNjyEDxpadNuTupq7an7xjSqk","addressRaw":{"0":70,"1":200,"2":17,"3":57,"4":167,"5":58,"6":228,"7":98,"8":184,"9":144,"10":52,"11":128,"12":63,"13":22,"14":82,"15":99,"16":21,"17":76,"18":38,"19":171,"20":24,"21":127,"22":177,"23":153,"24":145,"25":20,"26":61,"27":52,"28":82,"29":194,"30":223,"31":63},"isLocked":false,"meta":{},"publicKey":{"0":70,"1":200,"2":17,"3":57,"4":167,"5":58,"6":228,"7":98,"8":184,"9":144,"10":52,"11":128,"12":63,"13":22,"14":82,"15":99,"16":21,"17":76,"18":38,"19":171,"20":24,"21":127,"22":177,"23":153,"24":145,"25":20,"26":61,"27":52,"28":82,"29":194,"30":223,"31":63},"type":"sr25519","secretKey":{"0":24,"1":28,"2":142,"3":167,"4":100,"5":166,"6":225,"7":62,"8":152,"9":83,"10":129,"11":0,"12":153,"13":25,"14":162,"15":0,"16":255,"17":1,"18":75,"19":122,"20":215,"21":146,"22":125,"23":10,"24":76,"25":240,"26":180,"27":186,"28":112,"29":12,"30":191,"31":76,"32":136,"33":121,"34":125,"35":69,"36":2,"37":96,"38":175,"39":109,"40":81,"41":38,"42":218,"43":224,"44":117,"45":47,"46":228,"47":14,"48":246,"49":64,"50":240,"51":164,"52":207,"53":181,"54":250,"55":124,"56":252,"57":207,"58":176,"59":113,"60":226,"61":240,"62":247,"63":112}}}}}],"selectedAccount":"5DfWeADcWVtc4mwaV8EwKLgmNjyEDxpadNuTupq7an7xjSqk","endpoints":{"dev":"ws://127.0.0.1:9944","test-net":"wss://testnet.entropy.xyz"},"migration-version":1}

Specifically see secretKey, publicKey and addressRaw. Those are the result of calling JSON.stringify on a Uint8Array.

"secretKey":{"0":24,"1":28,"2":142,"3":167,"4":100,"5":166,"6":225,"7":62,"8":152,"9":83,"10":129,"11":0,"12":153,"13":25,"14":162,"15":0,"16":255,"17":1,"18":75,"19":122,"20":215,"21":146,"22":125,"23":10,"24":76,"25":240,"26":180,"27":186,"28":112,"29":12,"30":191,"31":76,"32":136,"33":121,"34":125,"35":69,"36":2,"37":96,"38":175,"39":109,"40":81,"41":38,"42":218,"43":224,"44":117,"45":47,"46":228,"47":14,"48":246,"49":64,"50":240,"51":164,"52":207,"53":181,"54":250,"55":124,"56":252,"57":207,"58":176,"59":113,"60":226,"61":240,"62":247,"63":112}

When we go JSON.parse ... those aren't converted back into the correct type... they're no just an Object.

:melting_face:

mixmix commented 3 days ago

Propose: