@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.
- package/index.js +8 -8
- package/index.js.map +1 -1
- package/package.json +2 -2
- package/v2/inter-app-communication-protocol.d.ts +2 -2
- package/v2/inter-app-communication-protocol.js +55 -57
- package/v2/inter-app-communication-protocol.js.map +1 -1
- package/v2/interfaces.js +1 -1
- package/v2/interfaces.js.map +1 -1
- package/v2/message.d.ts +2 -1
- package/v2/message.js +57 -51
- package/v2/message.js.map +1 -1
- package/v2/payloads/chunked-payload.d.ts +1 -0
- package/v2/payloads/chunked-payload.js +18 -17
- package/v2/payloads/chunked-payload.js.map +1 -1
- package/v2/payloads/full-payload.d.ts +1 -0
- package/v2/payloads/full-payload.js +33 -38
- package/v2/payloads/full-payload.js.map +1 -1
- package/v2/schemas/definitions/hex-string.d.ts +1 -1
- package/v2/schemas/schema.d.ts +1 -1
- package/v2/schemas/schema.js +1 -1
- package/v2/schemas/schema.js.map +1 -1
- package/v2/serializer.js +122 -70
- package/v2/serializer.js.map +1 -1
- package/v2/utils/generateId.js +6 -5
- package/v2/utils/generateId.js.map +1 -1
- package/v2/utils/json-to-rlp.js +52 -45
- package/v2/utils/json-to-rlp.js.map +1 -1
- package/v2/utils/toBuffer.d.ts +2 -1
- package/v2/utils/toBuffer.js +3 -2
- package/v2/utils/toBuffer.js.map +1 -1
- package/v2/validators/validators.js +79 -37
- package/v2/validators/validators.js.map +1 -1
- package/v3/iac-message-wrapper.d.ts +3 -3
- package/v3/iac-message-wrapper.js +43 -50
- package/v3/iac-message-wrapper.js.map +1 -1
- package/v3/interfaces.d.ts +1 -1
- package/v3/interfaces.js +6 -6
- package/v3/interfaces.js.map +1 -1
- package/v3/message.d.ts +2 -2
- package/v3/message.js +61 -53
- package/v3/message.js.map +1 -1
- package/v3/payload.js +25 -19
- package/v3/payload.js.map +1 -1
- package/v3/schemas/definitions/hex-string.d.ts +1 -1
- package/v3/schemas/schema.d.ts +1 -1
- package/v3/schemas/schema.js +1 -1
- package/v3/schemas/schema.js.map +1 -1
- package/v3/serializer.js +120 -69
- package/v3/serializer.js.map +1 -1
- package/v3/utils/generateId.js +8 -7
- package/v3/utils/generateId.js.map +1 -1
- package/v3/utils/json-to-rlp.js +58 -51
- package/v3/utils/json-to-rlp.js.map +1 -1
- package/v3/utils/toBuffer.d.ts +2 -1
- package/v3/validators/validators.js +77 -35
- package/v3/validators/validators.js.map +1 -1
package/v3/message.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Message = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const json_to_rlp_1 = require("./utils/json-to-rlp");
|
|
3
|
+
exports.Message = exports.isMessageDefinitionArray = void 0;
|
|
4
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
5
|
+
var interfaces_1 = require("./interfaces");
|
|
6
|
+
var serializer_1 = require("./serializer");
|
|
7
|
+
var generateId_1 = require("./utils/generateId");
|
|
8
|
+
var json_to_rlp_1 = require("./utils/json-to-rlp");
|
|
10
9
|
function isMessageDefinitionArray(value) {
|
|
11
10
|
return (Array.isArray(value) &&
|
|
12
11
|
value.length === 5 &&
|
|
@@ -16,29 +15,34 @@ function isMessageDefinitionArray(value) {
|
|
|
16
15
|
typeof value[3] === 'number' &&
|
|
17
16
|
Array.isArray(value[4]));
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
exports.isMessageDefinitionArray = isMessageDefinitionArray;
|
|
19
|
+
var Message = /** @class */ (function () {
|
|
20
|
+
function Message(type, protocol, payload, id, version) {
|
|
21
|
+
if (id === void 0) { id = (0, generateId_1.generateId)(generateId_1.ID_LENGTH); }
|
|
22
|
+
if (version === void 0) { version = 1; }
|
|
21
23
|
this.id = id;
|
|
22
24
|
this.type = type;
|
|
23
25
|
this.protocol = protocol;
|
|
24
26
|
this.payload = payload;
|
|
25
27
|
this.version = version;
|
|
26
28
|
}
|
|
27
|
-
asJson() {
|
|
29
|
+
Message.prototype.asJson = function () {
|
|
28
30
|
return {
|
|
29
31
|
type: this.type,
|
|
30
32
|
protocol: this.protocol,
|
|
31
33
|
id: this.id,
|
|
32
34
|
payload: this.payload
|
|
33
35
|
};
|
|
34
|
-
}
|
|
35
|
-
asArray
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
};
|
|
37
|
+
Message.prototype.asArray = function (serializer) {
|
|
38
|
+
if (serializer === void 0) { serializer = serializer_1.SerializerV3.getInstance(); }
|
|
39
|
+
var schemaInfos = serializer.getSchemas(this.type, this.protocol);
|
|
40
|
+
var lastError;
|
|
41
|
+
for (var _i = 0, schemaInfos_1 = schemaInfos; _i < schemaInfos_1.length; _i++) {
|
|
42
|
+
var schemaInfo = schemaInfos_1[_i];
|
|
39
43
|
try {
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
var schema = (0, json_to_rlp_1.unwrapSchema)(schemaInfo.schema);
|
|
45
|
+
var array = (0, json_to_rlp_1.jsonToArray)('root', schema, this.payload);
|
|
42
46
|
return [this.version, this.type, this.protocol, this.id, array];
|
|
43
47
|
}
|
|
44
48
|
catch (e) {
|
|
@@ -49,23 +53,25 @@ class Message {
|
|
|
49
53
|
throw lastError;
|
|
50
54
|
}
|
|
51
55
|
throw new Error('NO SCHEMA FOUND');
|
|
52
|
-
}
|
|
53
|
-
|
|
56
|
+
};
|
|
57
|
+
Message.fromDecoded = function (object) {
|
|
54
58
|
return new Message(object.type, object.protocol, object.payload, object.id);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
};
|
|
60
|
+
Message.fromEncoded = function (buf, serializer) {
|
|
61
|
+
if (serializer === void 0) { serializer = serializer_1.SerializerV3.getInstance(); }
|
|
62
|
+
var version = this.validateVersion(buf[0]);
|
|
63
|
+
var protocol = this.validateProtocol(buf[2], Array.from(serializer.getSupportedProtocols()));
|
|
64
|
+
var type = this.validateType(buf[1], protocol, serializer);
|
|
65
|
+
var id = this.validateId(buf[3]);
|
|
66
|
+
var encodedPayload = this.validatePayload(buf[4]);
|
|
67
|
+
var schemaInfos = serializer.getSchemas(type, protocol);
|
|
68
|
+
for (var _i = 0, schemaInfos_2 = schemaInfos; _i < schemaInfos_2.length; _i++) {
|
|
69
|
+
var schemaInfo = schemaInfos_2[_i];
|
|
64
70
|
try {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
var schema = (0, json_to_rlp_1.unwrapSchema)(schemaInfo.schema);
|
|
72
|
+
var schemaTransformer = schemaInfo.transformer;
|
|
73
|
+
var json = (0, json_to_rlp_1.rlpArrayToJson)(schema, encodedPayload);
|
|
74
|
+
var payload = schemaTransformer ? schemaTransformer(json) : json;
|
|
69
75
|
return (0, interfaces_1.success)(new Message(type, protocol, payload, id, version));
|
|
70
76
|
}
|
|
71
77
|
catch (e) {
|
|
@@ -73,12 +79,13 @@ class Message {
|
|
|
73
79
|
}
|
|
74
80
|
}
|
|
75
81
|
throw new Error('NO SCHEMA MATCHED');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return this.validateProperty('Version', version, (val)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
};
|
|
83
|
+
Message.validateVersion = function (version) {
|
|
84
|
+
return this.validateProperty('Version', version, function (val) { return val === 0 || val === 1; });
|
|
85
|
+
};
|
|
86
|
+
Message.validateType = function (value, protocol, serializer) {
|
|
87
|
+
if (serializer === void 0) { serializer = serializer_1.SerializerV3.getInstance(); }
|
|
88
|
+
return this.validateProperty('Type', value, function (val) {
|
|
82
89
|
try {
|
|
83
90
|
serializer.getSchemas(val, protocol);
|
|
84
91
|
return true;
|
|
@@ -87,25 +94,26 @@ class Message {
|
|
|
87
94
|
return false;
|
|
88
95
|
}
|
|
89
96
|
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return this.validateProperty('Protocol', protocol, (val)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return this.validateProperty('Id', id, (val)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return this.validateProperty('Payload', payload, ()
|
|
99
|
-
}
|
|
100
|
-
|
|
97
|
+
};
|
|
98
|
+
Message.validateProtocol = function (protocol, supportedProtocols) {
|
|
99
|
+
return this.validateProperty('Protocol', protocol, function (val) { return val.length === 0 || supportedProtocols.some(function (value) { return val === value || val.split('-')[0] === value; }); });
|
|
100
|
+
};
|
|
101
|
+
Message.validateId = function (id) {
|
|
102
|
+
return this.validateProperty('Id', id, function (val) { return val.toString().length <= generateId_1.ID_LENGTH; });
|
|
103
|
+
};
|
|
104
|
+
Message.validatePayload = function (payload) {
|
|
105
|
+
return this.validateProperty('Payload', payload, function () { return true; });
|
|
106
|
+
};
|
|
107
|
+
Message.validateProperty = function (property, value, validate) {
|
|
101
108
|
if (typeof value === 'undefined') {
|
|
102
|
-
throw new errors_1.SerializerError(errors_1.SerializerErrorType.PROPERTY_IS_EMPTY,
|
|
109
|
+
throw new errors_1.SerializerError(errors_1.SerializerErrorType.PROPERTY_IS_EMPTY, "".concat(property, " is empty"));
|
|
103
110
|
}
|
|
104
111
|
if (validate(value)) {
|
|
105
112
|
return value; // TODO: Use type guard?
|
|
106
113
|
}
|
|
107
|
-
throw new errors_1.SerializerError(errors_1.SerializerErrorType.PROPERTY_IS_EMPTY,
|
|
108
|
-
}
|
|
109
|
-
|
|
114
|
+
throw new errors_1.SerializerError(errors_1.SerializerErrorType.PROPERTY_IS_EMPTY, "".concat(property, " is invalid: \"").concat(value, "\""));
|
|
115
|
+
};
|
|
116
|
+
return Message;
|
|
117
|
+
}());
|
|
110
118
|
exports.Message = Message;
|
|
111
119
|
//# sourceMappingURL=message.js.map
|
package/v3/message.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/v3/message.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/v3/message.ts"],"names":[],"mappings":";;;AAAA,sDAAkF;AAGlF,2CAAuE;AAKvE,2CAA2C;AAG3C,iDAA0D;AAC1D,mDAA+E;AAqB/E,SAAgB,wBAAwB,CAAC,KAAc;IACrD,OAAO,CACL,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACpB,KAAK,CAAC,MAAM,KAAK,CAAC;QAClB,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ;QAC5B,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ;QAC5B,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ;QAC5B,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ;QAC5B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CACxB,CAAA;AACH,CAAC;AAVD,4DAUC;AAED;IAQE,iBACE,IAAoB,EACpB,QAAyB,EACzB,OAAoB,EACpB,EAAkC,EAClC,OAAmB;QADnB,mBAAA,EAAA,SAAa,uBAAU,EAAC,sBAAS,CAAC;QAClC,wBAAA,EAAA,WAAmB;QAEnB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;QACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAEM,wBAAM,GAAb;QACE,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,EAAE,EAAE,IAAI,CA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,SAAS,EAAE,OAAO,EAAE,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAA;IAChF,CAAC;IAEc,wBAAgB,GAA/B,UAAsC,QAAgB,EAAE,KAAQ,EAAE,QAA+B;QAC/F,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;YAChC,MAAM,IAAI,wBAAe,CAAC,4BAAmB,CAAC,iBAAiB,EAAE,UAAG,QAAQ,cAAW,CAAC,CAAA;SACzF;QAED,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE;YACnB,OAAO,KAAqB,CAAA,CAAC,wBAAwB;SACtD;QAED,MAAM,IAAI,wBAAe,CAAC,4BAAmB,CAAC,iBAAiB,EAAE,UAAG,QAAQ,4BAAiB,KAAK,OAAG,CAAC,CAAA;IACxG,CAAC;IACH,cAAC;AAAD,CAAC,AA/HD,IA+HC;AA/HY,0BAAO"}
|
package/v3/payload.js
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Payload = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
var interfaces_1 = require("./interfaces");
|
|
5
|
+
var message_1 = require("./message");
|
|
6
|
+
var serializer_1 = require("./serializer");
|
|
7
|
+
var Payload = /** @class */ (function () {
|
|
8
|
+
function Payload(messages) {
|
|
9
9
|
this.messages = messages;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
Payload.fromDecoded = function (object) {
|
|
12
12
|
return new Payload(object);
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
14
|
// public static fromEncoded(encoded: MessageDefinitionArray[], serializer: SerializerV3 = SerializerV3.getInstance()): Payload {
|
|
15
15
|
// const messages: IACMessageDefinitionObjectV3[] = encoded.map((message) => Message.fromEncoded(message, serializer).asJson())
|
|
16
16
|
// return new Payload(messages)
|
|
17
17
|
// }
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
Payload.fromEncoded = function (encoded, serializer) {
|
|
19
|
+
if (serializer === void 0) { serializer = serializer_1.SerializerV3.getInstance(); }
|
|
20
|
+
var messages = [];
|
|
21
|
+
var errors = [];
|
|
22
|
+
for (var _i = 0, encoded_1 = encoded; _i < encoded_1.length; _i++) {
|
|
23
|
+
var message = encoded_1[_i];
|
|
22
24
|
try {
|
|
23
|
-
|
|
25
|
+
var result = message_1.Message.fromEncoded(message, serializer);
|
|
24
26
|
if (result.ok) {
|
|
25
27
|
messages.push((0, interfaces_1.success)(result.value.asJson()));
|
|
26
28
|
}
|
|
@@ -33,13 +35,17 @@ class Payload {
|
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
return { payload: new Payload(messages), skippedPayload: errors };
|
|
36
|
-
}
|
|
37
|
-
asJson() {
|
|
38
|
+
};
|
|
39
|
+
Payload.prototype.asJson = function () {
|
|
38
40
|
return this.messages;
|
|
39
|
-
}
|
|
40
|
-
asArray
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
};
|
|
42
|
+
Payload.prototype.asArray = function (serializer) {
|
|
43
|
+
if (serializer === void 0) { serializer = serializer_1.SerializerV3.getInstance(); }
|
|
44
|
+
return this.messages.map(function (message) {
|
|
45
|
+
return message.ok ? (0, interfaces_1.success)(message_1.Message.fromDecoded(message.value).asArray(serializer)) : (0, interfaces_1.failure)(message.error);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
return Payload;
|
|
49
|
+
}());
|
|
44
50
|
exports.Payload = Payload;
|
|
45
51
|
//# sourceMappingURL=payload.js.map
|
package/v3/payload.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payload.js","sourceRoot":"","sources":["../../src/v3/payload.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"payload.js","sourceRoot":"","sources":["../../src/v3/payload.ts"],"names":[],"mappings":";;;AAAA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,yBAAY,CAAC,WAAW,EAAE;QAClE,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAC,OAAoD;YAC5E,OAAA,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,IAAA,oBAAO,EAAC,iBAAO,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,oBAAO,EAAE,OAA0B,CAAC,KAAK,CAAC;QAAzH,CAAyH,CAC1H,CAAA;IACH,CAAC;IACH,cAAC;AAAD,CAAC,AAhDD,IAgDC;AAhDY,0BAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type HexString = string;
|
|
1
|
+
export declare type HexString = string;
|
package/v3/schemas/schema.d.ts
CHANGED
package/v3/schemas/schema.js
CHANGED
|
@@ -10,5 +10,5 @@ var SchemaTypes;
|
|
|
10
10
|
SchemaTypes["NULL"] = "null";
|
|
11
11
|
SchemaTypes["ARRAY"] = "array";
|
|
12
12
|
SchemaTypes["OBJECT"] = "object";
|
|
13
|
-
})(SchemaTypes
|
|
13
|
+
})(SchemaTypes = exports.SchemaTypes || (exports.SchemaTypes = {}));
|
|
14
14
|
//# sourceMappingURL=schema.js.map
|
package/v3/schemas/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/v3/schemas/schema.ts"],"names":[],"mappings":";;;AAEA,IAAY,WAQX;AARD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,kCAAmB,CAAA;IACnB,4BAAa,CAAA;IACb,8BAAe,CAAA;IACf,gCAAiB,CAAA;AACnB,CAAC,EARW,WAAW,
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/v3/schemas/schema.ts"],"names":[],"mappings":";;;AAEA,IAAY,WAQX;AARD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,kCAAmB,CAAA;IACnB,4BAAa,CAAA;IACb,8BAAe,CAAA;IACf,gCAAiB,CAAA;AACnB,CAAC,EARW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAQtB"}
|
package/v3/serializer.js
CHANGED
|
@@ -1,22 +1,51 @@
|
|
|
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.SerializerV3 = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
static getInstance() {
|
|
14
|
-
if (SerializerV3.instance === undefined) {
|
|
15
|
-
SerializerV3.instance = new SerializerV3();
|
|
16
|
-
}
|
|
17
|
-
return SerializerV3.instance;
|
|
18
|
-
}
|
|
19
|
-
constructor() {
|
|
40
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
41
|
+
var ProtocolSymbols_1 = require("@airgap/coinlib-core/utils/ProtocolSymbols");
|
|
42
|
+
var iac_message_wrapper_1 = require("./iac-message-wrapper");
|
|
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');
|
|
47
|
+
var SerializerV3 = /** @class */ (function () {
|
|
48
|
+
function SerializerV3() {
|
|
20
49
|
this.schemas = new Map();
|
|
21
50
|
this.validators = new Map();
|
|
22
51
|
this.supportedProtocols = new Set();
|
|
@@ -24,32 +53,39 @@ class SerializerV3 {
|
|
|
24
53
|
this.addSchema(interfaces_1.IACMessageType.MessageSignRequest, { schema: messageSignRequest });
|
|
25
54
|
this.addSchema(interfaces_1.IACMessageType.MessageSignResponse, { schema: messageSignResponse });
|
|
26
55
|
}
|
|
27
|
-
|
|
56
|
+
SerializerV3.getInstance = function () {
|
|
57
|
+
if (SerializerV3.instance === undefined) {
|
|
58
|
+
SerializerV3.instance = new SerializerV3();
|
|
59
|
+
}
|
|
60
|
+
return SerializerV3.instance;
|
|
61
|
+
};
|
|
62
|
+
SerializerV3.addSchema = function (schemaId, schema, protocol) {
|
|
28
63
|
SerializerV3.getInstance().addSchema(schemaId, schema, protocol);
|
|
29
|
-
}
|
|
30
|
-
addSchema(schemaId, schema, protocol) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
64
|
+
};
|
|
65
|
+
SerializerV3.prototype.addSchema = function (schemaId, schema, protocol) {
|
|
66
|
+
var _a;
|
|
67
|
+
var protocolSpecificSchemaName = SerializerV3.getSchemaName(schemaId, protocol);
|
|
68
|
+
var schemas = (_a = this.schemas.get(protocolSpecificSchemaName)) !== null && _a !== void 0 ? _a : [];
|
|
69
|
+
if (schemas.some(function (el) { return el.schema === schema.schema; })) {
|
|
70
|
+
throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_ALREADY_EXISTS, "Schema ".concat(protocolSpecificSchemaName, " already exists"));
|
|
35
71
|
}
|
|
36
72
|
schemas.push(schema);
|
|
37
73
|
this.schemas.set(protocolSpecificSchemaName, schemas);
|
|
38
74
|
if (protocol) {
|
|
39
75
|
this.supportedProtocols.add(protocol);
|
|
40
76
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
77
|
+
};
|
|
78
|
+
SerializerV3.getSchemas = function (schemaId, protocol) {
|
|
43
79
|
return SerializerV3.getInstance().getSchemas(schemaId, protocol);
|
|
44
|
-
}
|
|
45
|
-
getSchemas(schemaId, protocol) {
|
|
46
|
-
|
|
47
|
-
|
|
80
|
+
};
|
|
81
|
+
SerializerV3.prototype.getSchemas = function (schemaId, protocol) {
|
|
82
|
+
var protocolSpecificSchemaName = SerializerV3.getSchemaName(schemaId, protocol);
|
|
83
|
+
var schemas;
|
|
48
84
|
if (this.schemas.has(protocolSpecificSchemaName)) {
|
|
49
85
|
schemas = this.schemas.get(protocolSpecificSchemaName);
|
|
50
86
|
}
|
|
51
87
|
else if (protocol !== undefined) {
|
|
52
|
-
|
|
88
|
+
var split = protocol.split('-');
|
|
53
89
|
// if protocol is a sub protocol and there is no schema defined for it, use the main protocol schema as the fallback
|
|
54
90
|
if (split.length >= 2) {
|
|
55
91
|
return this.getSchemas(schemaId, split[0]);
|
|
@@ -58,57 +94,72 @@ class SerializerV3 {
|
|
|
58
94
|
// Try to get the protocol specific scheme, if it doesn't exist fall back to the generic one
|
|
59
95
|
schemas = schemas !== undefined && schemas.length > 0 ? schemas : this.schemas.get(SerializerV3.getSchemaName(schemaId));
|
|
60
96
|
if (!schemas) {
|
|
61
|
-
throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_DOES_NOT_EXISTS,
|
|
97
|
+
throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_DOES_NOT_EXISTS, "Schema ".concat(protocolSpecificSchemaName, " does not exist"));
|
|
62
98
|
}
|
|
63
99
|
return schemas;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
100
|
+
};
|
|
101
|
+
SerializerV3.getSchemaName = function (schemaId, protocol) {
|
|
102
|
+
var schemaName = "".concat(schemaId, "-").concat(protocol);
|
|
67
103
|
if ((protocol !== undefined && schemaId === interfaces_1.IACMessageType.TransactionSignRequest) ||
|
|
68
104
|
schemaId === interfaces_1.IACMessageType.TransactionSignResponse) {
|
|
69
|
-
|
|
70
|
-
if (split.length >= 3 &&
|
|
71
|
-
return
|
|
105
|
+
var split = schemaName.split('-');
|
|
106
|
+
if (split.length >= 3 && "".concat(split[1], "-").concat(split[2]) === ProtocolSymbols_1.SubProtocolSymbols.ETH_ERC20) {
|
|
107
|
+
return "".concat(schemaId, "-").concat(ProtocolSymbols_1.SubProtocolSymbols.ETH_ERC20);
|
|
72
108
|
}
|
|
73
109
|
}
|
|
74
|
-
return protocol ?
|
|
75
|
-
}
|
|
76
|
-
|
|
110
|
+
return protocol ? "".concat(schemaId, "-").concat(protocol) : schemaId.toString();
|
|
111
|
+
};
|
|
112
|
+
SerializerV3.addValidator = function (protocol, validator) {
|
|
77
113
|
SerializerV3.getInstance().addValidator(protocol, validator);
|
|
78
|
-
}
|
|
79
|
-
addValidator(protocol, validator) {
|
|
114
|
+
};
|
|
115
|
+
SerializerV3.prototype.addValidator = function (protocol, validator) {
|
|
80
116
|
this.validators.set(protocol, validator);
|
|
81
|
-
}
|
|
82
|
-
getSupportedProtocols() {
|
|
117
|
+
};
|
|
118
|
+
SerializerV3.prototype.getSupportedProtocols = function () {
|
|
83
119
|
return this.supportedProtocols;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
120
|
+
};
|
|
121
|
+
SerializerV3.prototype.serialize = function (messages) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
123
|
+
var iacps;
|
|
124
|
+
var _this = this;
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
if (messages.every(function (message) {
|
|
127
|
+
return _this.getSchemas(message.type, message.protocol).length > 0;
|
|
128
|
+
})) {
|
|
129
|
+
iacps = iac_message_wrapper_1.IACMessageWrapper.fromDecoded(JSON.parse(JSON.stringify(messages)));
|
|
130
|
+
return [2 /*return*/, iacps.encoded(this)];
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
throw new errors_1.SerializerError(errors_1.SerializerErrorType.SCHEMA_DOES_NOT_EXISTS, "Unknown schema");
|
|
134
|
+
}
|
|
135
|
+
return [2 /*return*/];
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
SerializerV3.prototype.deserialize = function (data) {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
141
|
+
var _a, iACMessageWrapper, skippedPayload, deserializedIACMessageDefinitionObjects;
|
|
142
|
+
return __generator(this, function (_b) {
|
|
143
|
+
_a = iac_message_wrapper_1.IACMessageWrapper.fromEncoded(data, this), iACMessageWrapper = _a.iACMessageWrapper, skippedPayload = _a.skippedPayload;
|
|
144
|
+
deserializedIACMessageDefinitionObjects = iACMessageWrapper.payload.asJson();
|
|
145
|
+
return [2 /*return*/, { deserialize: deserializedIACMessageDefinitionObjects, skippedPayload: skippedPayload }];
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
SerializerV3.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); });
|
|
105
154
|
// TODO: Only use validator if it's a transaction
|
|
106
|
-
|
|
155
|
+
var validatorFactory = this.validators.get((_a = exactMatch !== null && exactMatch !== void 0 ? exactMatch : startsWith) !== null && _a !== void 0 ? _a : ProtocolSymbols_1.MainProtocolSymbols.ETH);
|
|
107
156
|
if (!validatorFactory) {
|
|
108
|
-
throw Error(
|
|
157
|
+
throw Error("Validator not registered for ".concat(protocolIdentifier, ", ").concat(exactMatch, ", ").concat(startsWith, ", ").concat(validatorFactory));
|
|
109
158
|
}
|
|
110
159
|
return validatorFactory.create();
|
|
111
|
-
}
|
|
112
|
-
|
|
160
|
+
};
|
|
161
|
+
SerializerV3.instance = undefined;
|
|
162
|
+
return SerializerV3;
|
|
163
|
+
}());
|
|
113
164
|
exports.SerializerV3 = SerializerV3;
|
|
114
165
|
//# sourceMappingURL=serializer.js.map
|
package/v3/serializer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../src/v3/serializer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../src/v3/serializer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAkF;AAClF,8EAAqH;AAErH,6DAAyD;AACzD,2CAAqD;AAKrD,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;IAcE;QAbiB,YAAO,GAA8B,IAAI,GAAG,EAAE,CAAA;QAC9C,eAAU,GAAsD,IAAI,GAAG,EAAE,CAAA;QACzE,uBAAkB,GAAgB,IAAI,GAAG,EAAE,CAAA;QAY1D,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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AAA,AAtID,IAsIC;AAtIY,oCAAY"}
|
package/v3/utils/generateId.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ID_LENGTH = void 0;
|
|
4
|
-
exports.generateId = generateId;
|
|
3
|
+
exports.generateId = exports.ID_LENGTH = void 0;
|
|
5
4
|
exports.ID_LENGTH = 8;
|
|
6
5
|
// Not very random, but IDs don't have to be because they are only used locally
|
|
7
|
-
function generateId(length
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
function generateId(length) {
|
|
7
|
+
if (length === void 0) { length = exports.ID_LENGTH; }
|
|
8
|
+
var characters = '0123456789';
|
|
9
|
+
var charactersLength = characters.length;
|
|
10
|
+
var result = '';
|
|
11
|
+
for (var i = 0; i < length; i++) {
|
|
12
12
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
13
13
|
}
|
|
14
14
|
return parseInt(result);
|
|
15
15
|
}
|
|
16
|
+
exports.generateId = generateId;
|
|
16
17
|
//# sourceMappingURL=generateId.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateId.js","sourceRoot":"","sources":["../../../src/v3/utils/generateId.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"generateId.js","sourceRoot":"","sources":["../../../src/v3/utils/generateId.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAW,CAAC,CAAA;AAElC,+EAA+E;AAC/E,SAAgB,UAAU,CAAC,MAA0B;IAA1B,uBAAA,EAAA,SAAiB,iBAAS;IACnD,IAAM,UAAU,GAAW,YAAY,CAAA;IACvC,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,QAAQ,CAAC,MAAM,CAAC,CAAA;AACzB,CAAC;AATD,gCASC"}
|