@airgap/serializer 0.13.45-beta.2 → 0.13.45-beta.3

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.
Files changed (56) hide show
  1. package/index.js +8 -8
  2. package/index.js.map +1 -1
  3. package/package.json +2 -2
  4. package/v2/inter-app-communication-protocol.d.ts +2 -2
  5. package/v2/inter-app-communication-protocol.js +57 -55
  6. package/v2/inter-app-communication-protocol.js.map +1 -1
  7. package/v2/interfaces.js +1 -1
  8. package/v2/interfaces.js.map +1 -1
  9. package/v2/message.d.ts +1 -2
  10. package/v2/message.js +51 -57
  11. package/v2/message.js.map +1 -1
  12. package/v2/payloads/chunked-payload.d.ts +0 -1
  13. package/v2/payloads/chunked-payload.js +17 -18
  14. package/v2/payloads/chunked-payload.js.map +1 -1
  15. package/v2/payloads/full-payload.d.ts +0 -1
  16. package/v2/payloads/full-payload.js +38 -33
  17. package/v2/payloads/full-payload.js.map +1 -1
  18. package/v2/schemas/definitions/hex-string.d.ts +1 -1
  19. package/v2/schemas/schema.d.ts +1 -1
  20. package/v2/schemas/schema.js +1 -1
  21. package/v2/schemas/schema.js.map +1 -1
  22. package/v2/serializer.js +70 -122
  23. package/v2/serializer.js.map +1 -1
  24. package/v2/utils/generateId.js +5 -6
  25. package/v2/utils/generateId.js.map +1 -1
  26. package/v2/utils/json-to-rlp.js +45 -52
  27. package/v2/utils/json-to-rlp.js.map +1 -1
  28. package/v2/utils/toBuffer.d.ts +1 -2
  29. package/v2/utils/toBuffer.js +2 -3
  30. package/v2/utils/toBuffer.js.map +1 -1
  31. package/v2/validators/validators.js +37 -79
  32. package/v2/validators/validators.js.map +1 -1
  33. package/v3/iac-message-wrapper.d.ts +3 -3
  34. package/v3/iac-message-wrapper.js +50 -43
  35. package/v3/iac-message-wrapper.js.map +1 -1
  36. package/v3/interfaces.d.ts +1 -1
  37. package/v3/interfaces.js +6 -6
  38. package/v3/interfaces.js.map +1 -1
  39. package/v3/message.d.ts +2 -2
  40. package/v3/message.js +53 -61
  41. package/v3/message.js.map +1 -1
  42. package/v3/payload.js +19 -25
  43. package/v3/payload.js.map +1 -1
  44. package/v3/schemas/definitions/hex-string.d.ts +1 -1
  45. package/v3/schemas/schema.d.ts +1 -1
  46. package/v3/schemas/schema.js +1 -1
  47. package/v3/schemas/schema.js.map +1 -1
  48. package/v3/serializer.js +69 -120
  49. package/v3/serializer.js.map +1 -1
  50. package/v3/utils/generateId.js +7 -8
  51. package/v3/utils/generateId.js.map +1 -1
  52. package/v3/utils/json-to-rlp.js +51 -58
  53. package/v3/utils/json-to-rlp.js.map +1 -1
  54. package/v3/utils/toBuffer.d.ts +1 -2
  55. package/v3/validators/validators.js +35 -77
  56. package/v3/validators/validators.js.map +1 -1
@@ -15,47 +15,52 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.FullPayload = void 0;
27
- var bs58check = __importStar(require("@airgap/coinlib-core/dependencies/src/bs58check-2.1.2/index"));
28
- var rlp = __importStar(require("@airgap/coinlib-core/dependencies/src/rlp-2.2.3/index"));
29
- var message_1 = require("../message");
30
- var serializer_1 = require("../serializer");
31
- var FullPayload = /** @class */ (function () {
32
- function FullPayload(messages) {
37
+ const bs58check = __importStar(require("@airgap/coinlib-core/dependencies/src/bs58check-2.1.2/index"));
38
+ const rlp = __importStar(require("@airgap/coinlib-core/dependencies/src/rlp-2.2.3/index"));
39
+ const message_1 = require("../message");
40
+ const serializer_1 = require("../serializer");
41
+ class FullPayload {
42
+ constructor(messages) {
33
43
  this.messages = messages;
34
44
  }
35
- FullPayload.fromDecoded = function (object) {
45
+ static fromDecoded(object) {
36
46
  return new FullPayload(object);
37
- };
38
- FullPayload.fromEncoded = function (buf, serializer) {
39
- if (serializer === void 0) { serializer = serializer_1.Serializer.getInstance(); }
40
- var messages = buf.map(function (buffer) { return message_1.Message.fromEncoded(buffer, serializer).asJson(); });
47
+ }
48
+ static fromEncoded(buf, serializer = serializer_1.Serializer.getInstance()) {
49
+ const messages = buf.map((buffer) => message_1.Message.fromEncoded(buffer, serializer).asJson());
41
50
  return new FullPayload(messages);
42
- };
43
- FullPayload.prototype.asJson = function () {
51
+ }
52
+ asJson() {
44
53
  return this.messages;
45
- };
46
- FullPayload.prototype.asArray = function (serializer) {
47
- if (serializer === void 0) { serializer = serializer_1.Serializer.getInstance(); }
48
- return this.messages.map(function (message) { return message_1.Message.fromDecoded(message, serializer).asArray(); });
49
- };
50
- FullPayload.prototype.asBuffer = function (serializer) {
51
- if (serializer === void 0) { serializer = serializer_1.Serializer.getInstance(); }
54
+ }
55
+ asArray(serializer = serializer_1.Serializer.getInstance()) {
56
+ return this.messages.map((message) => message_1.Message.fromDecoded(message, serializer).asArray());
57
+ }
58
+ asBuffer(serializer = serializer_1.Serializer.getInstance()) {
52
59
  return rlp.encode(this.asArray(serializer));
53
- };
54
- FullPayload.prototype.asString = function (serializer) {
55
- if (serializer === void 0) { serializer = serializer_1.Serializer.getInstance(); }
60
+ }
61
+ asString(serializer = serializer_1.Serializer.getInstance()) {
56
62
  return bs58check.encode(this.asBuffer(serializer));
57
- };
58
- return FullPayload;
59
- }());
63
+ }
64
+ }
60
65
  exports.FullPayload = FullPayload;
61
66
  //# sourceMappingURL=full-payload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"full-payload.js","sourceRoot":"","sources":["../../../src/v2/payloads/full-payload.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qGAAwF;AACxF,yFAA4E;AAE5E,sCAAgE;AAIhE,4CAA0C;AAE1C;IAGE,qBAAY,QAAsC;QAChD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAEa,uBAAW,GAAzB,UAA0B,MAAoC;QAC5D,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;IAChC,CAAC;IACa,uBAAW,GAAzB,UAA0B,GAAa,EAAE,UAAiD;QAAjD,2BAAA,EAAA,aAAyB,uBAAU,CAAC,WAAW,EAAE;QACxF,IAAM,QAAQ,GAAiC,GAAG,CAAC,GAAG,CAAC,UAAC,MAAM,IAAK,OAAA,iBAAO,CAAC,WAAW,CAAC,MAAa,EAAE,UAAU,CAAC,CAAC,MAAM,EAAE,EAAvD,CAAuD,CAAC,CAAA;QAE3H,OAAO,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;IAEM,4BAAM,GAAb;QACE,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAEM,6BAAO,GAAd,UAAe,UAAiD;QAAjD,2BAAA,EAAA,aAAyB,uBAAU,CAAC,WAAW,EAAE;QAC9D,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAC,OAAmC,IAAK,OAAA,iBAAO,CAAC,WAAW,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,OAAO,EAAE,EAAlD,CAAkD,CAAC,CAAA;IACvH,CAAC;IAEM,8BAA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,CAAC,GAAG,CAAC,CAAC,OAAmC,EAAE,EAAE,CAAC,iBAAO,CAAC,WAAW,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;IACvH,CAAC;IAEM,QAAQ,CAAC,aAAyB,uBAAU,CAAC,WAAW,EAAE;QAC/D,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;IAC7C,CAAC;IAEM,QAAQ,CAAC,aAAyB,uBAAU,CAAC,WAAW,EAAE;QAC/D,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAA;IACpD,CAAC;CACF;AA/BD,kCA+BC"}
@@ -1 +1 @@
1
- export declare type HexString = string;
1
+ export type HexString = string;
@@ -1,4 +1,4 @@
1
- export declare type SchemaTransformer = (value: any) => any;
1
+ export type SchemaTransformer = (value: any) => any;
2
2
  export declare enum SchemaTypes {
3
3
  STRING = "string",
4
4
  NUMBER = "number",
@@ -11,5 +11,5 @@ var SchemaTypes;
11
11
  SchemaTypes["ARRAY"] = "array";
12
12
  SchemaTypes["OBJECT"] = "object";
13
13
  SchemaTypes["HEX_STRING"] = "hexString"; // TODO: Should we do it like that?
14
- })(SchemaTypes = exports.SchemaTypes || (exports.SchemaTypes = {}));
14
+ })(SchemaTypes || (exports.SchemaTypes = SchemaTypes = {}));
15
15
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/v2/schemas/schema.ts"],"names":[],"mappings":";;;AAEA,IAAY,WASX;AATD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,kCAAmB,CAAA;IACnB,4BAAa,CAAA;IACb,8BAAe,CAAA;IACf,gCAAiB,CAAA;IACjB,uCAAwB,CAAA,CAAC,mCAAmC;AAC9D,CAAC,EATW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAStB"}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/v2/schemas/schema.ts"],"names":[],"mappings":";;;AAEA,IAAY,WASX;AATD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,kCAAmB,CAAA;IACnB,4BAAa,CAAA;IACb,8BAAe,CAAA;IACf,gCAAiB,CAAA;IACjB,uCAAwB,CAAA,CAAC,mCAAmC;AAC9D,CAAC,EATW,WAAW,2BAAX,WAAW,QAStB"}
package/v2/serializer.js CHANGED
@@ -1,165 +1,113 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.Serializer = exports.IACPayloadType = void 0;
40
- var errors_1 = require("@airgap/coinlib-core/errors");
41
- var ProtocolSymbols_1 = require("@airgap/coinlib-core/utils/ProtocolSymbols");
42
- var inter_app_communication_protocol_1 = require("./inter-app-communication-protocol");
43
- var interfaces_1 = require("./interfaces");
44
- var accountShareResponse = require('./schemas/generated/account-share-response.json');
45
- var messageSignRequest = require('./schemas/generated/message-sign-request.json');
46
- var messageSignResponse = require('./schemas/generated/message-sign-response.json');
4
+ const errors_1 = require("@airgap/coinlib-core/errors");
5
+ const ProtocolSymbols_1 = require("@airgap/coinlib-core/utils/ProtocolSymbols");
6
+ const inter_app_communication_protocol_1 = require("./inter-app-communication-protocol");
7
+ const interfaces_1 = require("./interfaces");
8
+ const accountShareResponse = require('./schemas/generated/account-share-response.json');
9
+ const messageSignRequest = require('./schemas/generated/message-sign-request.json');
10
+ const messageSignResponse = require('./schemas/generated/message-sign-response.json');
47
11
  var IACPayloadType;
48
12
  (function (IACPayloadType) {
49
13
  IACPayloadType[IACPayloadType["FULL"] = 0] = "FULL";
50
14
  IACPayloadType[IACPayloadType["CHUNKED"] = 1] = "CHUNKED";
51
- })(IACPayloadType = exports.IACPayloadType || (exports.IACPayloadType = {}));
52
- var Serializer = /** @class */ (function () {
53
- function Serializer() {
15
+ })(IACPayloadType || (exports.IACPayloadType = IACPayloadType = {}));
16
+ class Serializer {
17
+ static { this.instance = undefined; }
18
+ static getInstance() {
19
+ if (Serializer.instance === undefined) {
20
+ Serializer.instance = new Serializer();
21
+ }
22
+ return Serializer.instance;
23
+ }
24
+ constructor() {
54
25
  this.schemas = new Map();
55
26
  this.validators = new Map();
56
27
  this.addSchema(interfaces_1.IACMessageType.AccountShareResponse, { schema: accountShareResponse });
57
28
  this.addSchema(interfaces_1.IACMessageType.MessageSignRequest, { schema: messageSignRequest });
58
29
  this.addSchema(interfaces_1.IACMessageType.MessageSignResponse, { schema: messageSignResponse });
59
30
  }
60
- Serializer.getInstance = function () {
61
- if (Serializer.instance === undefined) {
62
- Serializer.instance = new Serializer();
63
- }
64
- return Serializer.instance;
65
- };
66
- Serializer.addSchema = function (schemaId, schema, protocol) {
31
+ static addSchema(schemaId, schema, protocol) {
67
32
  Serializer.getInstance().addSchema(schemaId, schema, protocol);
68
- };
69
- Serializer.prototype.addSchema = function (schemaId, schema, protocol) {
70
- var protocolSpecificSchemaName = Serializer.getSchemaName(schemaId, protocol);
33
+ }
34
+ addSchema(schemaId, schema, protocol) {
35
+ const protocolSpecificSchemaName = Serializer.getSchemaName(schemaId, protocol);
71
36
  if (this.schemas.has(protocolSpecificSchemaName)) {
72
- throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_ALREADY_EXISTS, "Schema ".concat(protocolSpecificSchemaName, " already exists"));
37
+ throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_ALREADY_EXISTS, `Schema ${protocolSpecificSchemaName} already exists`);
73
38
  }
74
39
  this.schemas.set(protocolSpecificSchemaName, schema);
75
- };
76
- Serializer.getSchema = function (schemaId, protocol) {
40
+ }
41
+ static getSchema(schemaId, protocol) {
77
42
  return Serializer.getInstance().getSchema(schemaId, protocol);
78
- };
79
- Serializer.prototype.getSchema = function (schemaId, protocol) {
80
- var protocolSpecificSchemaName = Serializer.getSchemaName(schemaId, protocol);
81
- var schema;
43
+ }
44
+ getSchema(schemaId, protocol) {
45
+ const protocolSpecificSchemaName = Serializer.getSchemaName(schemaId, protocol);
46
+ let schema;
82
47
  if (this.schemas.has(protocolSpecificSchemaName)) {
83
48
  schema = this.schemas.get(protocolSpecificSchemaName);
84
49
  }
85
50
  else if (protocol !== undefined) {
86
- var split = protocol.split('-');
51
+ const split = protocol.split('-');
87
52
  // if protocol is a sub protocol and there is no schema defined for it, use the main protocol schema as the fallback
88
53
  if (split.length >= 2) {
89
54
  return this.getSchema(schemaId, split[0]);
90
55
  }
91
56
  }
92
57
  // Try to get the protocol specific scheme, if it doesn't exist fall back to the generic one
93
- schema = schema !== null && schema !== void 0 ? schema : this.schemas.get(Serializer.getSchemaName(schemaId));
58
+ schema = schema ?? this.schemas.get(Serializer.getSchemaName(schemaId));
94
59
  if (!schema) {
95
- throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_DOES_NOT_EXISTS, "Schema ".concat(protocolSpecificSchemaName, " does not exist"));
60
+ throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_DOES_NOT_EXISTS, `Schema ${protocolSpecificSchemaName} does not exist`);
96
61
  }
97
62
  return schema;
98
- };
99
- Serializer.getSchemaName = function (schemaId, protocol) {
100
- var schemaName = "".concat(schemaId, "-").concat(protocol);
63
+ }
64
+ static getSchemaName(schemaId, protocol) {
65
+ const schemaName = `${schemaId}-${protocol}`;
101
66
  if ((protocol !== undefined && schemaId === interfaces_1.IACMessageType.TransactionSignRequest) ||
102
67
  schemaId === interfaces_1.IACMessageType.TransactionSignResponse) {
103
- var split = schemaName.split('-');
104
- if (split.length >= 3 && "".concat(split[1], "-").concat(split[2]) === ProtocolSymbols_1.SubProtocolSymbols.ETH_ERC20) {
105
- return "".concat(schemaId, "-").concat(ProtocolSymbols_1.SubProtocolSymbols.ETH_ERC20);
68
+ const split = schemaName.split('-');
69
+ if (split.length >= 3 && `${split[1]}-${split[2]}` === ProtocolSymbols_1.SubProtocolSymbols.ETH_ERC20) {
70
+ return `${schemaId}-${ProtocolSymbols_1.SubProtocolSymbols.ETH_ERC20}`;
106
71
  }
107
72
  }
108
- return protocol ? "".concat(schemaId, "-").concat(protocol) : schemaId.toString();
109
- };
110
- Serializer.addValidator = function (protocol, validator) {
73
+ return protocol ? `${schemaId}-${protocol}` : schemaId.toString();
74
+ }
75
+ static addValidator(protocol, validator) {
111
76
  Serializer.getInstance().addValidator(protocol, validator);
112
- };
113
- Serializer.prototype.addValidator = function (protocol, validator) {
77
+ }
78
+ addValidator(protocol, validator) {
114
79
  this.validators.set(protocol, validator);
115
- };
116
- Serializer.prototype.serialize = function (messages, singleChunkSize, multiChunkSize) {
117
- if (singleChunkSize === void 0) { singleChunkSize = 0; }
118
- if (multiChunkSize === void 0) { multiChunkSize = 0; }
119
- return __awaiter(this, void 0, void 0, function () {
120
- var iacps;
121
- var _this = this;
122
- return __generator(this, function (_a) {
123
- if (messages.every(function (message) {
124
- return _this.getSchema(message.type, message.protocol);
125
- })) {
126
- iacps = inter_app_communication_protocol_1.IACProtocol.fromDecoded(JSON.parse(JSON.stringify(messages)), singleChunkSize, multiChunkSize, this);
127
- return [2 /*return*/, iacps.map(function (iac) { return iac.encoded(_this); })];
128
- }
129
- else {
130
- throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_DOES_NOT_EXISTS, "Unknown schema");
131
- }
132
- return [2 /*return*/];
133
- });
134
- });
135
- };
136
- Serializer.prototype.deserialize = function (data) {
137
- return __awaiter(this, void 0, void 0, function () {
138
- var result, deserializedIACMessageDefinitionObjects;
139
- return __generator(this, function (_a) {
140
- result = inter_app_communication_protocol_1.IACProtocol.fromEncoded(data, this);
141
- deserializedIACMessageDefinitionObjects = result
142
- .map(function (el) { return el.payload; })
143
- .map(function (el) { return el.asJson(); })
144
- .reduce(function (pv, cv) { return pv.concat.apply(pv, cv); }, []);
145
- return [2 /*return*/, deserializedIACMessageDefinitionObjects];
146
- });
147
- });
148
- };
149
- Serializer.prototype.serializationValidatorByProtocolIdentifier = function (protocolIdentifier) {
150
- var _a;
151
- var validatorsKeys = Array.from(this.validators.keys());
152
- var exactMatch = validatorsKeys.find(function (protocol) { return protocolIdentifier === protocol; });
153
- var startsWith = validatorsKeys.find(function (protocol) { return protocolIdentifier.startsWith(protocol); });
80
+ }
81
+ async serialize(messages, singleChunkSize = 0, multiChunkSize = 0) {
82
+ if (messages.every((message) => {
83
+ return this.getSchema(message.type, message.protocol);
84
+ })) {
85
+ const iacps = inter_app_communication_protocol_1.IACProtocol.fromDecoded(JSON.parse(JSON.stringify(messages)), singleChunkSize, multiChunkSize, this);
86
+ return iacps.map((iac) => iac.encoded(this));
87
+ }
88
+ else {
89
+ throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_DOES_NOT_EXISTS, `Unknown schema`);
90
+ }
91
+ }
92
+ async deserialize(data) {
93
+ const result = inter_app_communication_protocol_1.IACProtocol.fromEncoded(data, this);
94
+ const deserializedIACMessageDefinitionObjects = result
95
+ .map((el) => el.payload)
96
+ .map((el) => el.asJson())
97
+ .reduce((pv, cv) => pv.concat(...cv), []);
98
+ return deserializedIACMessageDefinitionObjects;
99
+ }
100
+ serializationValidatorByProtocolIdentifier(protocolIdentifier) {
101
+ const validatorsKeys = Array.from(this.validators.keys());
102
+ const exactMatch = validatorsKeys.find((protocol) => protocolIdentifier === protocol);
103
+ const startsWith = validatorsKeys.find((protocol) => protocolIdentifier.startsWith(protocol));
154
104
  // TODO: Only use validator if it's a transaction
155
- var validatorFactory = this.validators.get((_a = exactMatch !== null && exactMatch !== void 0 ? exactMatch : startsWith) !== null && _a !== void 0 ? _a : ProtocolSymbols_1.MainProtocolSymbols.ETH);
105
+ const validatorFactory = this.validators.get(exactMatch ?? startsWith ?? ProtocolSymbols_1.MainProtocolSymbols.ETH);
156
106
  if (!validatorFactory) {
157
- throw Error("Validator not registered for ".concat(protocolIdentifier, ", ").concat(exactMatch, ", ").concat(startsWith, ", ").concat(validatorFactory));
107
+ throw Error(`Validator not registered for ${protocolIdentifier}, ${exactMatch}, ${startsWith}, ${validatorFactory}`);
158
108
  }
159
109
  return validatorFactory.create();
160
- };
161
- Serializer.instance = undefined;
162
- return Serializer;
163
- }());
110
+ }
111
+ }
164
112
  exports.Serializer = Serializer;
165
113
  //# sourceMappingURL=serializer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../src/v2/serializer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAkF;AAClF,8EAAqH;AAErH,uFAAgE;AAChE,2CAA6C;AAO7C,IAAM,oBAAoB,GAAe,OAAO,CAAC,iDAAiD,CAAC,CAAA;AAEnG,IAAM,kBAAkB,GAAe,OAAO,CAAC,+CAA+C,CAAC,CAAA;AAC/F,IAAM,mBAAmB,GAAe,OAAO,CAAC,gDAAgD,CAAC,CAAA;AAEjG,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,mDAAQ,CAAA;IACR,yDAAW,CAAA;AACb,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB;AAED;IAaE;QAZiB,YAAO,GAA4B,IAAI,GAAG,EAAE,CAAA;QAC5C,eAAU,GAAsD,IAAI,GAAG,EAAE,CAAA;QAYxF,IAAI,CAAC,SAAS,CAAC,2BAAc,CAAC,oBAAoB,EAAE,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAC,CAAA;QACrF,IAAI,CAAC,SAAS,CAAC,2BAAc,CAAC,kBAAkB,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAA;QACjF,IAAI,CAAC,SAAS,CAAC,2BAAc,CAAC,mBAAmB,EAAE,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAA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M,UAAU,GAAgC,cAAc,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAA;QAC1H,iDAAiD;QACjD,MAAM,gBAAgB,GAA4C,IAAI,CAAC,UAAU,CAAC,GAAG,CACnF,UAAU,IAAI,UAAU,IAAI,qCAAmB,CAAC,GAAG,CACpD,CAAA;QAED,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,MAAM,KAAK,CAAC,gCAAgC,kBAAkB,KAAK,UAAU,KAAK,UAAU,KAAK,gBAAgB,EAAE,CAAC,CAAA;QACtH,CAAC;QAED,OAAO,gBAAgB,CAAC,MAAM,EAAE,CAAA;IAClC,CAAC;;AA9HH,gCA+HC"}
@@ -1,15 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateIdV2 = void 0;
3
+ exports.generateIdV2 = generateIdV2;
4
4
  // Not very random, but IDs don't have to be because they are only used locally
5
5
  function generateIdV2(length) {
6
- var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
7
- var charactersLength = characters.length;
8
- var result = '';
9
- for (var i = 0; i < length; i++) {
6
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
7
+ const charactersLength = characters.length;
8
+ let result = '';
9
+ for (let i = 0; i < length; i++) {
10
10
  result += characters.charAt(Math.floor(Math.random() * charactersLength));
11
11
  }
12
12
  return result;
13
13
  }
14
- exports.generateIdV2 = generateIdV2;
15
14
  //# sourceMappingURL=generateId.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateId.js","sourceRoot":"","sources":["../../../src/v2/utils/generateId.ts"],"names":[],"mappings":";;;AAAA,+EAA+E;AAC/E,SAAgB,YAAY,CAAC,MAAc;IACzC,IAAM,UAAU,GAAW,gEAAgE,CAAA;IAC3F,IAAM,gBAAgB,GAAW,UAAU,CAAC,MAAM,CAAA;IAClD,IAAI,MAAM,GAAW,EAAE,CAAA;IACvB,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;QACvC,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAA;KAC1E;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AATD,oCASC"}
1
+ {"version":3,"file":"generateId.js","sourceRoot":"","sources":["../../../src/v2/utils/generateId.ts"],"names":[],"mappings":";;AACA,oCASC;AAVD,+EAA+E;AAC/E,SAAgB,YAAY,CAAC,MAAc;IACzC,MAAM,UAAU,GAAW,gEAAgE,CAAA;IAC3F,MAAM,gBAAgB,GAAW,UAAU,CAAC,MAAM,CAAA;IAClD,IAAI,MAAM,GAAW,EAAE,CAAA;IACvB,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAA;IAC3E,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -1,34 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rlpArrayToJson = exports.jsonToArray = exports.unwrapSchema = exports.getDefinitionByRefPath = void 0;
4
- var errors_1 = require("@airgap/coinlib-core/errors");
5
- var coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
6
- var assert_1 = require("@airgap/coinlib-core/utils/assert");
7
- var schema_1 = require("../schemas/schema");
8
- function log() {
9
- var args = [];
10
- for (var _i = 0; _i < arguments.length; _i++) {
11
- args[_i] = arguments[_i];
12
- }
13
- var loggingEnabled = false;
3
+ exports.getDefinitionByRefPath = getDefinitionByRefPath;
4
+ exports.unwrapSchema = unwrapSchema;
5
+ exports.jsonToArray = jsonToArray;
6
+ exports.rlpArrayToJson = rlpArrayToJson;
7
+ const errors_1 = require("@airgap/coinlib-core/errors");
8
+ const coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
9
+ const assert_1 = require("@airgap/coinlib-core/utils/assert");
10
+ const schema_1 = require("../schemas/schema");
11
+ function log(...args) {
12
+ const loggingEnabled = false;
14
13
  if (loggingEnabled) {
15
14
  // tslint:disable-next-line:no-console
16
- console.log.apply(console, args);
15
+ console.log(...args);
17
16
  }
18
17
  }
19
18
  function getDefinitionByRefPath(schema, refPath) {
20
- var mainDefinitionName = refPath.split('/').slice(-1)[0];
21
- var definitions = schema.definitions;
19
+ const mainDefinitionName = refPath.split('/').slice(-1)[0];
20
+ const definitions = schema.definitions;
22
21
  return definitions[mainDefinitionName];
23
22
  }
24
- exports.getDefinitionByRefPath = getDefinitionByRefPath;
25
23
  function unwrapSchema(schema) {
26
24
  log('UNWRAPPING SCHEMA', schema);
27
25
  return getDefinitionByRefPath(schema, schema.$ref);
28
26
  }
29
- exports.unwrapSchema = unwrapSchema;
30
27
  function typeError(key, expectedType, value) {
31
- return new errors_1.InvalidSchemaType("".concat(key, ": expected type \"").concat(expectedType, "\", but got \"").concat(typeof value, "\", value: ").concat(typeof value === 'object' ? JSON.stringify(value) : value));
28
+ return new errors_1.InvalidSchemaType(`${key}: expected type "${expectedType}", but got "${typeof value}", value: ${typeof value === 'object' ? JSON.stringify(value) : value}`);
32
29
  }
33
30
  function checkType(key, expectedType, value, callback) {
34
31
  if (expectedType === 'array' && Array.isArray(value)) {
@@ -42,51 +39,50 @@ function checkType(key, expectedType, value, callback) {
42
39
  }
43
40
  }
44
41
  function getTypeFromSchemaDefinition(schema) {
45
- var _a;
46
- return (_a = schema === null || schema === void 0 ? void 0 : schema.type) !== null && _a !== void 0 ? _a : ((schema === null || schema === void 0 ? void 0 : schema.$ref) === '#/definitions/HexString' ? schema_1.SchemaTypes.HEX_STRING : schema_1.SchemaTypes.STRING);
42
+ return schema?.type ?? (schema?.$ref === '#/definitions/HexString' ? schema_1.SchemaTypes.HEX_STRING : schema_1.SchemaTypes.STRING);
47
43
  }
48
44
  function jsonToArray(key, schema, value) {
49
- var type = getTypeFromSchemaDefinition(schema);
45
+ const type = getTypeFromSchemaDefinition(schema);
50
46
  switch (type) {
51
47
  case schema_1.SchemaTypes.STRING:
52
- return checkType(key, 'string', value, function (arg) {
53
- log("Parsing key ".concat(key, " as string, which results in ").concat(arg));
48
+ return checkType(key, 'string', value, (arg) => {
49
+ log(`Parsing key ${key} as string, which results in ${arg}`);
54
50
  if (arg.startsWith('0x')) {
55
- throw new errors_1.InvalidString("string \"".concat(value, "\" starts with \"0x\". This causes problems with RLP. Please use the \"HexString\" type instead of \"string\""));
51
+ throw new errors_1.InvalidString(`string "${value}" starts with "0x". This causes problems with RLP. Please use the "HexString" type instead of "string"`);
56
52
  }
57
53
  return arg;
58
54
  });
59
55
  case schema_1.SchemaTypes.HEX_STRING:
60
- return checkType(key, 'string', value, function (arg) {
61
- log("Parsing key ".concat(key, " as hex-string, which results in ").concat(arg));
56
+ return checkType(key, 'string', value, (arg) => {
57
+ log(`Parsing key ${key} as hex-string, which results in ${arg}`);
62
58
  if (!arg.startsWith('0x')) {
63
- throw new errors_1.InvalidHexString("\"".concat(value, "\" does not start with \"0x\""));
59
+ throw new errors_1.InvalidHexString(`"${value}" does not start with "0x"`);
64
60
  }
65
61
  return arg.substr(2); // Remove the '0x'
66
62
  });
67
63
  case schema_1.SchemaTypes.NUMBER:
68
64
  case schema_1.SchemaTypes.INTEGER:
69
- return checkType(key, 'number', value, function (arg) {
70
- log("Parsing key ".concat(key, " as number, which results in ").concat(arg.toString()));
65
+ return checkType(key, 'number', value, (arg) => {
66
+ log(`Parsing key ${key} as number, which results in ${arg.toString()}`);
71
67
  return arg.toString();
72
68
  });
73
69
  case schema_1.SchemaTypes.BOOLEAN:
74
- return checkType(key, 'boolean', value, function (arg) {
75
- log("Parsing key ".concat(key, " as boolean, which results in ").concat(arg ? '1' : '0'));
70
+ return checkType(key, 'boolean', value, (arg) => {
71
+ log(`Parsing key ${key} as boolean, which results in ${arg ? '1' : '0'}`);
76
72
  return arg ? '1' : '0';
77
73
  });
78
74
  case schema_1.SchemaTypes.NULL:
79
75
  if (typeof value === 'undefined') {
80
- log("Parsing key ".concat(key, " as undefined, which results in ''"));
76
+ log(`Parsing key ${key} as undefined, which results in ''`);
81
77
  return '';
82
78
  }
83
79
  else {
84
80
  throw typeError(key, 'undefined', value);
85
81
  }
86
82
  case schema_1.SchemaTypes.ARRAY:
87
- return checkType(key, 'array', value, function (arg) {
88
- return arg.map(function (element, index) {
89
- var items = schema.items;
83
+ return checkType(key, 'array', value, (arg) => {
84
+ return arg.map((element, index) => {
85
+ const items = schema.items;
90
86
  if (Array.isArray(items)) {
91
87
  return jsonToArray(key, items[index], element);
92
88
  }
@@ -96,15 +92,14 @@ function jsonToArray(key, schema, value) {
96
92
  });
97
93
  });
98
94
  case schema_1.SchemaTypes.OBJECT:
99
- return checkType(key, 'object', value, function (arg) {
100
- var properties = schema.properties;
101
- var keys = Object.keys(properties).sort();
102
- var out = [];
103
- for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
104
- var propertyKey = keys_1[_i];
95
+ return checkType(key, 'object', value, (arg) => {
96
+ const properties = schema.properties;
97
+ const keys = Object.keys(properties).sort();
98
+ const out = [];
99
+ for (const propertyKey of keys) {
105
100
  out.push(jsonToArray(propertyKey, properties[propertyKey], arg[propertyKey]));
106
101
  }
107
- log("Parsing key ".concat(key, " as object, which results in ").concat(out));
102
+ log(`Parsing key ${key} as object, which results in ${out}`);
108
103
  return out;
109
104
  });
110
105
  default:
@@ -112,12 +107,11 @@ function jsonToArray(key, schema, value) {
112
107
  throw new errors_1.InvalidSchemaType();
113
108
  }
114
109
  }
115
- exports.jsonToArray = jsonToArray;
116
110
  function decode(schemaItem, decoded) {
117
111
  if (typeof decoded === 'undefined') {
118
112
  throw new errors_1.InvalidPayloadError();
119
113
  }
120
- var type = getTypeFromSchemaDefinition(schemaItem);
114
+ const type = getTypeFromSchemaDefinition(schemaItem);
121
115
  switch (type) {
122
116
  case schema_1.SchemaTypes.BOOLEAN:
123
117
  if (decoded.toString() !== '') {
@@ -127,7 +121,7 @@ function decode(schemaItem, decoded) {
127
121
  case schema_1.SchemaTypes.STRING:
128
122
  return decoded.toString();
129
123
  case schema_1.SchemaTypes.HEX_STRING:
130
- return "0x".concat(decoded.toString());
124
+ return `0x${decoded.toString()}`;
131
125
  case schema_1.SchemaTypes.NUMBER:
132
126
  case schema_1.SchemaTypes.INTEGER:
133
127
  if (decoded.toString() !== '') {
@@ -137,8 +131,8 @@ function decode(schemaItem, decoded) {
137
131
  case schema_1.SchemaTypes.NULL:
138
132
  return undefined;
139
133
  case schema_1.SchemaTypes.ARRAY:
140
- return decoded.map(function (decodedElement, index) {
141
- var items = schemaItem.items;
134
+ return decoded.map((decodedElement, index) => {
135
+ const items = schemaItem.items;
142
136
  if (Array.isArray(items)) {
143
137
  return decode(items[index], decodedElement);
144
138
  }
@@ -154,9 +148,9 @@ function decode(schemaItem, decoded) {
154
148
  }
155
149
  }
156
150
  function rlpArrayToJson(schema, decoded) {
157
- var outObject = {};
151
+ const outObject = {};
158
152
  if (schema.type === schema_1.SchemaTypes.OBJECT) {
159
- var newShema = schema.properties;
153
+ const newShema = schema.properties;
160
154
  if (newShema) {
161
155
  return rlpArrayToJson(newShema, decoded);
162
156
  }
@@ -164,14 +158,13 @@ function rlpArrayToJson(schema, decoded) {
164
158
  throw new errors_1.NotFoundError(coinlib_error_1.Domain.SERIALIZER, 'Schema not available.');
165
159
  }
166
160
  }
167
- var keys = Object.keys(schema).sort();
161
+ const keys = Object.keys(schema).sort();
168
162
  log(keys);
169
- for (var i = 0; i < keys.length; i++) {
170
- var key = keys[i];
163
+ for (let i = 0; i < keys.length; i++) {
164
+ const key = keys[i];
171
165
  log(schema);
172
166
  outObject[key] = decode(schema[key], decoded[i]);
173
167
  }
174
168
  return outObject;
175
169
  }
176
- exports.rlpArrayToJson = rlpArrayToJson;
177
170
  //# sourceMappingURL=json-to-rlp.js.map