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

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 +55 -57
  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 +2 -1
  10. package/v2/message.js +57 -51
  11. package/v2/message.js.map +1 -1
  12. package/v2/payloads/chunked-payload.d.ts +1 -0
  13. package/v2/payloads/chunked-payload.js +18 -17
  14. package/v2/payloads/chunked-payload.js.map +1 -1
  15. package/v2/payloads/full-payload.d.ts +1 -0
  16. package/v2/payloads/full-payload.js +33 -38
  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 +122 -70
  23. package/v2/serializer.js.map +1 -1
  24. package/v2/utils/generateId.js +6 -5
  25. package/v2/utils/generateId.js.map +1 -1
  26. package/v2/utils/json-to-rlp.js +52 -45
  27. package/v2/utils/json-to-rlp.js.map +1 -1
  28. package/v2/utils/toBuffer.d.ts +2 -1
  29. package/v2/utils/toBuffer.js +3 -2
  30. package/v2/utils/toBuffer.js.map +1 -1
  31. package/v2/validators/validators.js +79 -37
  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 +43 -50
  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 +61 -53
  41. package/v3/message.js.map +1 -1
  42. package/v3/payload.js +25 -19
  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 +120 -69
  49. package/v3/serializer.js.map +1 -1
  50. package/v3/utils/generateId.js +8 -7
  51. package/v3/utils/generateId.js.map +1 -1
  52. package/v3/utils/json-to-rlp.js +58 -51
  53. package/v3/utils/json-to-rlp.js.map +1 -1
  54. package/v3/utils/toBuffer.d.ts +2 -1
  55. package/v3/validators/validators.js +77 -35
  56. package/v3/validators/validators.js.map +1 -1
@@ -15,52 +15,47 @@ 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 () {
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
- })();
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
+ };
35
25
  Object.defineProperty(exports, "__esModule", { value: true });
36
26
  exports.FullPayload = void 0;
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) {
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) {
43
33
  this.messages = messages;
44
34
  }
45
- static fromDecoded(object) {
35
+ FullPayload.fromDecoded = function (object) {
46
36
  return new FullPayload(object);
47
- }
48
- static fromEncoded(buf, serializer = serializer_1.Serializer.getInstance()) {
49
- const messages = buf.map((buffer) => message_1.Message.fromEncoded(buffer, serializer).asJson());
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(); });
50
41
  return new FullPayload(messages);
51
- }
52
- asJson() {
42
+ };
43
+ FullPayload.prototype.asJson = function () {
53
44
  return this.messages;
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()) {
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(); }
59
52
  return rlp.encode(this.asArray(serializer));
60
- }
61
- asString(serializer = serializer_1.Serializer.getInstance()) {
53
+ };
54
+ FullPayload.prototype.asString = function (serializer) {
55
+ if (serializer === void 0) { serializer = serializer_1.Serializer.getInstance(); }
62
56
  return bs58check.encode(this.asBuffer(serializer));
63
- }
64
- }
57
+ };
58
+ return FullPayload;
59
+ }());
65
60
  exports.FullPayload = FullPayload;
66
61
  //# 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,uGAAwF;AACxF,2FAA4E;AAE5E,wCAAgE;AAIhE,8CAA0C;AAE1C,MAAa,WAAW;IAGtB,YAAY,QAAsC;QAChD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAEM,MAAM,CAAC,WAAW,CAAC,MAAoC;QAC5D,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;IAChC,CAAC;IACM,MAAM,CAAC,WAAW,CAAC,GAAa,EAAE,aAAyB,uBAAU,CAAC,WAAW,EAAE;QACxF,MAAM,QAAQ,GAAiC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAO,CAAC,WAAW,CAAC,MAAa,EAAE,UAAU,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;QAE3H,OAAO,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAEM,OAAO,CAAC,aAAyB,uBAAU,CAAC,WAAW,EAAE;QAC9D,OAAO,IAAI,CAAC,QAAQ,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,CAA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,CAAkD,CAAC,CAAA;IACvH,CAAC;IAEM,8BAAQ,GAAf,UAAgB,UAAiD;QAAjD,2BAAA,EAAA,aAAyB,uBAAU,CAAC,WAAW,EAAE;QAC/D,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;IAC7C,CAAC;IAEM,8BAAQ,GAAf,UAAgB,UAAiD;QAAjD,2BAAA,EAAA,aAAyB,uBAAU,CAAC,WAAW,EAAE;QAC/D,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAA;IACpD,CAAC;IACH,kBAAC;AAAD,CAAC,AA/BD,IA+BC;AA/BY,kCAAW"}
@@ -1 +1 @@
1
- export type HexString = string;
1
+ export declare type HexString = string;
@@ -1,4 +1,4 @@
1
- export type SchemaTransformer = (value: any) => any;
1
+ export declare 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 = SchemaTypes = {}));
14
+ })(SchemaTypes = exports.SchemaTypes || (exports.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,2BAAX,WAAW,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,GAAX,mBAAW,KAAX,mBAAW,QAStB"}
package/v2/serializer.js CHANGED
@@ -1,113 +1,165 @@
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
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
39
  exports.Serializer = exports.IACPayloadType = void 0;
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');
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');
11
47
  var IACPayloadType;
12
48
  (function (IACPayloadType) {
13
49
  IACPayloadType[IACPayloadType["FULL"] = 0] = "FULL";
14
50
  IACPayloadType[IACPayloadType["CHUNKED"] = 1] = "CHUNKED";
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() {
51
+ })(IACPayloadType = exports.IACPayloadType || (exports.IACPayloadType = {}));
52
+ var Serializer = /** @class */ (function () {
53
+ function Serializer() {
25
54
  this.schemas = new Map();
26
55
  this.validators = new Map();
27
56
  this.addSchema(interfaces_1.IACMessageType.AccountShareResponse, { schema: accountShareResponse });
28
57
  this.addSchema(interfaces_1.IACMessageType.MessageSignRequest, { schema: messageSignRequest });
29
58
  this.addSchema(interfaces_1.IACMessageType.MessageSignResponse, { schema: messageSignResponse });
30
59
  }
31
- static addSchema(schemaId, schema, protocol) {
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) {
32
67
  Serializer.getInstance().addSchema(schemaId, schema, protocol);
33
- }
34
- addSchema(schemaId, schema, protocol) {
35
- const protocolSpecificSchemaName = Serializer.getSchemaName(schemaId, protocol);
68
+ };
69
+ Serializer.prototype.addSchema = function (schemaId, schema, protocol) {
70
+ var protocolSpecificSchemaName = Serializer.getSchemaName(schemaId, protocol);
36
71
  if (this.schemas.has(protocolSpecificSchemaName)) {
37
- throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_ALREADY_EXISTS, `Schema ${protocolSpecificSchemaName} already exists`);
72
+ throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_ALREADY_EXISTS, "Schema ".concat(protocolSpecificSchemaName, " already exists"));
38
73
  }
39
74
  this.schemas.set(protocolSpecificSchemaName, schema);
40
- }
41
- static getSchema(schemaId, protocol) {
75
+ };
76
+ Serializer.getSchema = function (schemaId, protocol) {
42
77
  return Serializer.getInstance().getSchema(schemaId, protocol);
43
- }
44
- getSchema(schemaId, protocol) {
45
- const protocolSpecificSchemaName = Serializer.getSchemaName(schemaId, protocol);
46
- let schema;
78
+ };
79
+ Serializer.prototype.getSchema = function (schemaId, protocol) {
80
+ var protocolSpecificSchemaName = Serializer.getSchemaName(schemaId, protocol);
81
+ var schema;
47
82
  if (this.schemas.has(protocolSpecificSchemaName)) {
48
83
  schema = this.schemas.get(protocolSpecificSchemaName);
49
84
  }
50
85
  else if (protocol !== undefined) {
51
- const split = protocol.split('-');
86
+ var split = protocol.split('-');
52
87
  // if protocol is a sub protocol and there is no schema defined for it, use the main protocol schema as the fallback
53
88
  if (split.length >= 2) {
54
89
  return this.getSchema(schemaId, split[0]);
55
90
  }
56
91
  }
57
92
  // Try to get the protocol specific scheme, if it doesn't exist fall back to the generic one
58
- schema = schema ?? this.schemas.get(Serializer.getSchemaName(schemaId));
93
+ schema = schema !== null && schema !== void 0 ? schema : this.schemas.get(Serializer.getSchemaName(schemaId));
59
94
  if (!schema) {
60
- throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_DOES_NOT_EXISTS, `Schema ${protocolSpecificSchemaName} does not exist`);
95
+ throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_DOES_NOT_EXISTS, "Schema ".concat(protocolSpecificSchemaName, " does not exist"));
61
96
  }
62
97
  return schema;
63
- }
64
- static getSchemaName(schemaId, protocol) {
65
- const schemaName = `${schemaId}-${protocol}`;
98
+ };
99
+ Serializer.getSchemaName = function (schemaId, protocol) {
100
+ var schemaName = "".concat(schemaId, "-").concat(protocol);
66
101
  if ((protocol !== undefined && schemaId === interfaces_1.IACMessageType.TransactionSignRequest) ||
67
102
  schemaId === interfaces_1.IACMessageType.TransactionSignResponse) {
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}`;
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);
71
106
  }
72
107
  }
73
- return protocol ? `${schemaId}-${protocol}` : schemaId.toString();
74
- }
75
- static addValidator(protocol, validator) {
108
+ return protocol ? "".concat(schemaId, "-").concat(protocol) : schemaId.toString();
109
+ };
110
+ Serializer.addValidator = function (protocol, validator) {
76
111
  Serializer.getInstance().addValidator(protocol, validator);
77
- }
78
- addValidator(protocol, validator) {
112
+ };
113
+ Serializer.prototype.addValidator = function (protocol, validator) {
79
114
  this.validators.set(protocol, validator);
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));
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); });
104
154
  // TODO: Only use validator if it's a transaction
105
- const validatorFactory = this.validators.get(exactMatch ?? startsWith ?? ProtocolSymbols_1.MainProtocolSymbols.ETH);
155
+ var validatorFactory = this.validators.get((_a = exactMatch !== null && exactMatch !== void 0 ? exactMatch : startsWith) !== null && _a !== void 0 ? _a : ProtocolSymbols_1.MainProtocolSymbols.ETH);
106
156
  if (!validatorFactory) {
107
- throw Error(`Validator not registered for ${protocolIdentifier}, ${exactMatch}, ${startsWith}, ${validatorFactory}`);
157
+ throw Error("Validator not registered for ".concat(protocolIdentifier, ", ").concat(exactMatch, ", ").concat(startsWith, ", ").concat(validatorFactory));
108
158
  }
109
159
  return validatorFactory.create();
110
- }
111
- }
160
+ };
161
+ Serializer.instance = undefined;
162
+ return Serializer;
163
+ }());
112
164
  exports.Serializer = Serializer;
113
165
  //# sourceMappingURL=serializer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../src/v2/serializer.ts"],"names":[],"mappings":";;;AAAA,wDAAkF;AAClF,gFAAqH;AAErH,yFAAgE;AAChE,6CAA6C;AAO7C,MAAM,oBAAoB,GAAe,OAAO,CAAC,iDAAiD,CAAC,CAAA;AAEnG,MAAM,kBAAkB,GAAe,OAAO,CAAC,+CAA+C,CAAC,CAAA;AAC/F,MAAM,mBAAmB,GAAe,OAAO,CAAC,gDAAgD,CAAC,CAAA;AAEjG,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,mDAAQ,CAAA;IACR,yDAAW,CAAA;AACb,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB;AAED,MAAa,UAAU;aAIN,aAAQ,GAA2B,SAAS,AAApC,CAAoC;IACpD,MAAM,CAAC,WAAW;QACvB,IAAI,UAAU,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACtC,UAAU,CAAC,QAAQ,GAAG,IAAI,UAAU,EAAE,CAAA;QACxC,CAAC;QAED,OAAO,UAAU,CAAC,QAAQ,CAAA;IAC5B,CAAC;IAED;QAZiB,YAAO,GAA4B,IAAI,GAAG,EAAE,CAAA;QAC5C,eAAU,GAAsD,IAAI,GAAG,EAAE,CAAA;QAYxF,IAAI,CAAC,SAAS,CAAC,2BAAc,CAAC,oBAAoB,EAAE,E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AAC,QAAQ,IAAK,OAAA,kBAAkB,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAvC,CAAuC,CAAC,CAAA;QAC1H,iDAAiD;QACjD,IAAM,gBAAgB,GAA4C,IAAI,CAAC,UAAU,CAAC,GAAG,CACnF,MAAA,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,UAAU,mCAAI,qCAAmB,CAAC,GAAG,CACpD,CAAA;QAED,IAAI,CAAC,gBAAgB,EAAE;YACrB,MAAM,KAAK,CAAC,uCAAgC,kBAAkB,eAAK,UAAU,eAAK,UAAU,eAAK,gBAAgB,CAAE,CAAC,CAAA;SACrH;QAED,OAAO,gBAAgB,CAAC,MAAM,EAAE,CAAA;IAClC,CAAC;IA1Hc,mBAAQ,GAA2B,SAAS,CAAA;IA2H7D,iBAAC;CAAA,AA/HD,IA+HC;AA/HY,gCAAU"}
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateIdV2 = generateIdV2;
3
+ exports.generateIdV2 = void 0;
4
4
  // Not very random, but IDs don't have to be because they are only used locally
5
5
  function generateIdV2(length) {
6
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
7
- const charactersLength = characters.length;
8
- let result = '';
9
- for (let i = 0; i < length; i++) {
6
+ var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
7
+ var charactersLength = characters.length;
8
+ var result = '';
9
+ for (var 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;
14
15
  //# sourceMappingURL=generateId.js.map
@@ -1 +1 @@
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
+ {"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,31 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
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;
13
14
  if (loggingEnabled) {
14
15
  // tslint:disable-next-line:no-console
15
- console.log(...args);
16
+ console.log.apply(console, args);
16
17
  }
17
18
  }
18
19
  function getDefinitionByRefPath(schema, refPath) {
19
- const mainDefinitionName = refPath.split('/').slice(-1)[0];
20
- const definitions = schema.definitions;
20
+ var mainDefinitionName = refPath.split('/').slice(-1)[0];
21
+ var definitions = schema.definitions;
21
22
  return definitions[mainDefinitionName];
22
23
  }
24
+ exports.getDefinitionByRefPath = getDefinitionByRefPath;
23
25
  function unwrapSchema(schema) {
24
26
  log('UNWRAPPING SCHEMA', schema);
25
27
  return getDefinitionByRefPath(schema, schema.$ref);
26
28
  }
29
+ exports.unwrapSchema = unwrapSchema;
27
30
  function typeError(key, expectedType, value) {
28
- return new errors_1.InvalidSchemaType(`${key}: expected type "${expectedType}", but got "${typeof value}", value: ${typeof value === 'object' ? JSON.stringify(value) : 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));
29
32
  }
30
33
  function checkType(key, expectedType, value, callback) {
31
34
  if (expectedType === 'array' && Array.isArray(value)) {
@@ -39,50 +42,51 @@ function checkType(key, expectedType, value, callback) {
39
42
  }
40
43
  }
41
44
  function getTypeFromSchemaDefinition(schema) {
42
- return schema?.type ?? (schema?.$ref === '#/definitions/HexString' ? schema_1.SchemaTypes.HEX_STRING : schema_1.SchemaTypes.STRING);
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);
43
47
  }
44
48
  function jsonToArray(key, schema, value) {
45
- const type = getTypeFromSchemaDefinition(schema);
49
+ var type = getTypeFromSchemaDefinition(schema);
46
50
  switch (type) {
47
51
  case schema_1.SchemaTypes.STRING:
48
- return checkType(key, 'string', value, (arg) => {
49
- log(`Parsing key ${key} as string, which results in ${arg}`);
52
+ return checkType(key, 'string', value, function (arg) {
53
+ log("Parsing key ".concat(key, " as string, which results in ").concat(arg));
50
54
  if (arg.startsWith('0x')) {
51
- throw new errors_1.InvalidString(`string "${value}" starts with "0x". This causes problems with RLP. Please use the "HexString" type instead of "string"`);
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\""));
52
56
  }
53
57
  return arg;
54
58
  });
55
59
  case schema_1.SchemaTypes.HEX_STRING:
56
- return checkType(key, 'string', value, (arg) => {
57
- log(`Parsing key ${key} as hex-string, which results in ${arg}`);
60
+ return checkType(key, 'string', value, function (arg) {
61
+ log("Parsing key ".concat(key, " as hex-string, which results in ").concat(arg));
58
62
  if (!arg.startsWith('0x')) {
59
- throw new errors_1.InvalidHexString(`"${value}" does not start with "0x"`);
63
+ throw new errors_1.InvalidHexString("\"".concat(value, "\" does not start with \"0x\""));
60
64
  }
61
65
  return arg.substr(2); // Remove the '0x'
62
66
  });
63
67
  case schema_1.SchemaTypes.NUMBER:
64
68
  case schema_1.SchemaTypes.INTEGER:
65
- return checkType(key, 'number', value, (arg) => {
66
- log(`Parsing key ${key} as number, which results in ${arg.toString()}`);
69
+ return checkType(key, 'number', value, function (arg) {
70
+ log("Parsing key ".concat(key, " as number, which results in ").concat(arg.toString()));
67
71
  return arg.toString();
68
72
  });
69
73
  case schema_1.SchemaTypes.BOOLEAN:
70
- return checkType(key, 'boolean', value, (arg) => {
71
- log(`Parsing key ${key} as boolean, which results in ${arg ? '1' : '0'}`);
74
+ return checkType(key, 'boolean', value, function (arg) {
75
+ log("Parsing key ".concat(key, " as boolean, which results in ").concat(arg ? '1' : '0'));
72
76
  return arg ? '1' : '0';
73
77
  });
74
78
  case schema_1.SchemaTypes.NULL:
75
79
  if (typeof value === 'undefined') {
76
- log(`Parsing key ${key} as undefined, which results in ''`);
80
+ log("Parsing key ".concat(key, " as undefined, which results in ''"));
77
81
  return '';
78
82
  }
79
83
  else {
80
84
  throw typeError(key, 'undefined', value);
81
85
  }
82
86
  case schema_1.SchemaTypes.ARRAY:
83
- return checkType(key, 'array', value, (arg) => {
84
- return arg.map((element, index) => {
85
- const items = schema.items;
87
+ return checkType(key, 'array', value, function (arg) {
88
+ return arg.map(function (element, index) {
89
+ var items = schema.items;
86
90
  if (Array.isArray(items)) {
87
91
  return jsonToArray(key, items[index], element);
88
92
  }
@@ -92,14 +96,15 @@ function jsonToArray(key, schema, value) {
92
96
  });
93
97
  });
94
98
  case schema_1.SchemaTypes.OBJECT:
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) {
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];
100
105
  out.push(jsonToArray(propertyKey, properties[propertyKey], arg[propertyKey]));
101
106
  }
102
- log(`Parsing key ${key} as object, which results in ${out}`);
107
+ log("Parsing key ".concat(key, " as object, which results in ").concat(out));
103
108
  return out;
104
109
  });
105
110
  default:
@@ -107,11 +112,12 @@ function jsonToArray(key, schema, value) {
107
112
  throw new errors_1.InvalidSchemaType();
108
113
  }
109
114
  }
115
+ exports.jsonToArray = jsonToArray;
110
116
  function decode(schemaItem, decoded) {
111
117
  if (typeof decoded === 'undefined') {
112
118
  throw new errors_1.InvalidPayloadError();
113
119
  }
114
- const type = getTypeFromSchemaDefinition(schemaItem);
120
+ var type = getTypeFromSchemaDefinition(schemaItem);
115
121
  switch (type) {
116
122
  case schema_1.SchemaTypes.BOOLEAN:
117
123
  if (decoded.toString() !== '') {
@@ -121,7 +127,7 @@ function decode(schemaItem, decoded) {
121
127
  case schema_1.SchemaTypes.STRING:
122
128
  return decoded.toString();
123
129
  case schema_1.SchemaTypes.HEX_STRING:
124
- return `0x${decoded.toString()}`;
130
+ return "0x".concat(decoded.toString());
125
131
  case schema_1.SchemaTypes.NUMBER:
126
132
  case schema_1.SchemaTypes.INTEGER:
127
133
  if (decoded.toString() !== '') {
@@ -131,8 +137,8 @@ function decode(schemaItem, decoded) {
131
137
  case schema_1.SchemaTypes.NULL:
132
138
  return undefined;
133
139
  case schema_1.SchemaTypes.ARRAY:
134
- return decoded.map((decodedElement, index) => {
135
- const items = schemaItem.items;
140
+ return decoded.map(function (decodedElement, index) {
141
+ var items = schemaItem.items;
136
142
  if (Array.isArray(items)) {
137
143
  return decode(items[index], decodedElement);
138
144
  }
@@ -148,9 +154,9 @@ function decode(schemaItem, decoded) {
148
154
  }
149
155
  }
150
156
  function rlpArrayToJson(schema, decoded) {
151
- const outObject = {};
157
+ var outObject = {};
152
158
  if (schema.type === schema_1.SchemaTypes.OBJECT) {
153
- const newShema = schema.properties;
159
+ var newShema = schema.properties;
154
160
  if (newShema) {
155
161
  return rlpArrayToJson(newShema, decoded);
156
162
  }
@@ -158,13 +164,14 @@ function rlpArrayToJson(schema, decoded) {
158
164
  throw new errors_1.NotFoundError(coinlib_error_1.Domain.SERIALIZER, 'Schema not available.');
159
165
  }
160
166
  }
161
- const keys = Object.keys(schema).sort();
167
+ var keys = Object.keys(schema).sort();
162
168
  log(keys);
163
- for (let i = 0; i < keys.length; i++) {
164
- const key = keys[i];
169
+ for (var i = 0; i < keys.length; i++) {
170
+ var key = keys[i];
165
171
  log(schema);
166
172
  outObject[key] = decode(schema[key], decoded[i]);
167
173
  }
168
174
  return outObject;
169
175
  }
176
+ exports.rlpArrayToJson = rlpArrayToJson;
170
177
  //# sourceMappingURL=json-to-rlp.js.map