koilib 9.4.0 → 9.4.1
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/dist/koinos.js +282 -5
- package/dist/koinos.min.js +1 -1
- package/lib/Serializer.js +30 -4
- package/lib/Serializer.js.map +1 -1
- package/lib/browser/Serializer.js +30 -4
- package/lib/browser/Serializer.js.map +1 -1
- package/package.json +1 -1
- package/src/Serializer.ts +28 -4
package/lib/Serializer.js
CHANGED
|
@@ -29,6 +29,29 @@ const protobufjs_1 = require("protobufjs");
|
|
|
29
29
|
const koinosPbToProto = __importStar(require("@roamin/koinos-pb-to-proto"));
|
|
30
30
|
const utils_1 = require("./utils");
|
|
31
31
|
const googleProtobufDescriptor_1 = require("./protobuf/googleProtobufDescriptor");
|
|
32
|
+
/**
|
|
33
|
+
* Google namespace of the types with koilib's complete copy of
|
|
34
|
+
* descriptor.proto. Contracts include descriptor.proto only because
|
|
35
|
+
* koinos/options.proto extends it, and the embedded copy can be
|
|
36
|
+
* incomplete (missing FieldDescriptorProto.Label, for instance), so
|
|
37
|
+
* its types are replaced while any other google types are kept.
|
|
38
|
+
*/
|
|
39
|
+
function withGoogleDescriptor(google) {
|
|
40
|
+
var _a;
|
|
41
|
+
const descriptor = googleProtobufDescriptor_1.googleProtobufDescriptor.google.nested.protobuf;
|
|
42
|
+
const embedded = (_a = google === null || google === void 0 ? void 0 : google.nested) === null || _a === void 0 ? void 0 : _a.protobuf;
|
|
43
|
+
return {
|
|
44
|
+
...google,
|
|
45
|
+
nested: {
|
|
46
|
+
...google === null || google === void 0 ? void 0 : google.nested,
|
|
47
|
+
protobuf: {
|
|
48
|
+
...embedded,
|
|
49
|
+
...descriptor,
|
|
50
|
+
nested: { ...embedded === null || embedded === void 0 ? void 0 : embedded.nested, ...descriptor.nested },
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
32
55
|
const OP_BYTES_1 = "(btype)";
|
|
33
56
|
const OP_BYTES_2 = "(koinos.btype)";
|
|
34
57
|
const nativeTypes = [
|
|
@@ -106,6 +129,7 @@ const nativeTypes = [
|
|
|
106
129
|
*/
|
|
107
130
|
class Serializer {
|
|
108
131
|
constructor(types, opts) {
|
|
132
|
+
var _a;
|
|
109
133
|
/**
|
|
110
134
|
* Preformat bytes for base64url, base58 or hex string
|
|
111
135
|
*/
|
|
@@ -121,18 +145,20 @@ class Serializer {
|
|
|
121
145
|
this.types = types;
|
|
122
146
|
if (typeof types === "string") {
|
|
123
147
|
const protos = koinosPbToProto.convert((0, utils_1.decodeBase64)(types));
|
|
124
|
-
this.root =
|
|
148
|
+
this.root = protobufjs_1.Root.fromJSON({ nested: googleProtobufDescriptor_1.googleProtobufDescriptor });
|
|
125
149
|
for (const proto of protos) {
|
|
150
|
+
// descriptor.proto is proto2 and loses its labels when converted
|
|
151
|
+
// to text, so use the copy loaded above instead
|
|
152
|
+
if (proto.file === "google/protobuf/descriptor.proto")
|
|
153
|
+
continue;
|
|
126
154
|
(0, protobufjs_1.parse)(proto.definition, this.root, { keepCase: true });
|
|
127
155
|
}
|
|
128
156
|
}
|
|
129
157
|
else {
|
|
130
158
|
this.root = protobufjs_1.Root.fromJSON({
|
|
131
159
|
nested: {
|
|
132
|
-
// import google protobuf descriptor if not present
|
|
133
|
-
...googleProtobufDescriptor_1.googleProtobufDescriptor,
|
|
134
|
-
// import types
|
|
135
160
|
...types.nested,
|
|
161
|
+
google: withGoogleDescriptor((_a = types.nested) === null || _a === void 0 ? void 0 : _a.google),
|
|
136
162
|
},
|
|
137
163
|
});
|
|
138
164
|
}
|
package/lib/Serializer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Serializer.js","sourceRoot":"","sources":["../src/Serializer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAqD;AACrD,2CAA2D;AAC3D,4EAA8D;AAE9D,mCAKiB;AACjB,kFAA+E;AAE/E,M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c,GAClB,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,cAAc,MAAK,SAAS;YAChC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,WAAW;YACjC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;QAC1B,IAAI,eAAe,EAAE;YACnB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,CAAM,CAAC;SACpE;QACD,OAAO,MAAW,CAAC;IACrB,CAAC;CACF;AAtTD,gCAsTC;AAED,kBAAe,UAAU,CAAC"}
|
|
@@ -29,6 +29,29 @@ const protobufjs_1 = require("protobufjs");
|
|
|
29
29
|
const koinosPbToProto = __importStar(require("@roamin/koinos-pb-to-proto"));
|
|
30
30
|
const utils_1 = require("./utils");
|
|
31
31
|
const googleProtobufDescriptor_1 = require("./protobuf/googleProtobufDescriptor");
|
|
32
|
+
/**
|
|
33
|
+
* Google namespace of the types with koilib's complete copy of
|
|
34
|
+
* descriptor.proto. Contracts include descriptor.proto only because
|
|
35
|
+
* koinos/options.proto extends it, and the embedded copy can be
|
|
36
|
+
* incomplete (missing FieldDescriptorProto.Label, for instance), so
|
|
37
|
+
* its types are replaced while any other google types are kept.
|
|
38
|
+
*/
|
|
39
|
+
function withGoogleDescriptor(google) {
|
|
40
|
+
var _a;
|
|
41
|
+
const descriptor = googleProtobufDescriptor_1.googleProtobufDescriptor.google.nested.protobuf;
|
|
42
|
+
const embedded = (_a = google === null || google === void 0 ? void 0 : google.nested) === null || _a === void 0 ? void 0 : _a.protobuf;
|
|
43
|
+
return {
|
|
44
|
+
...google,
|
|
45
|
+
nested: {
|
|
46
|
+
...google === null || google === void 0 ? void 0 : google.nested,
|
|
47
|
+
protobuf: {
|
|
48
|
+
...embedded,
|
|
49
|
+
...descriptor,
|
|
50
|
+
nested: { ...embedded === null || embedded === void 0 ? void 0 : embedded.nested, ...descriptor.nested },
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
32
55
|
const OP_BYTES_1 = "(btype)";
|
|
33
56
|
const OP_BYTES_2 = "(koinos.btype)";
|
|
34
57
|
const nativeTypes = [
|
|
@@ -106,6 +129,7 @@ const nativeTypes = [
|
|
|
106
129
|
*/
|
|
107
130
|
class Serializer {
|
|
108
131
|
constructor(types, opts) {
|
|
132
|
+
var _a;
|
|
109
133
|
/**
|
|
110
134
|
* Preformat bytes for base64url, base58 or hex string
|
|
111
135
|
*/
|
|
@@ -121,18 +145,20 @@ class Serializer {
|
|
|
121
145
|
this.types = types;
|
|
122
146
|
if (typeof types === "string") {
|
|
123
147
|
const protos = koinosPbToProto.convert((0, utils_1.decodeBase64)(types));
|
|
124
|
-
this.root =
|
|
148
|
+
this.root = protobufjs_1.Root.fromJSON({ nested: googleProtobufDescriptor_1.googleProtobufDescriptor });
|
|
125
149
|
for (const proto of protos) {
|
|
150
|
+
// descriptor.proto is proto2 and loses its labels when converted
|
|
151
|
+
// to text, so use the copy loaded above instead
|
|
152
|
+
if (proto.file === "google/protobuf/descriptor.proto")
|
|
153
|
+
continue;
|
|
126
154
|
(0, protobufjs_1.parse)(proto.definition, this.root, { keepCase: true });
|
|
127
155
|
}
|
|
128
156
|
}
|
|
129
157
|
else {
|
|
130
158
|
this.root = protobufjs_1.Root.fromJSON({
|
|
131
159
|
nested: {
|
|
132
|
-
// import google protobuf descriptor if not present
|
|
133
|
-
...googleProtobufDescriptor_1.googleProtobufDescriptor,
|
|
134
|
-
// import types
|
|
135
160
|
...types.nested,
|
|
161
|
+
google: withGoogleDescriptor((_a = types.nested) === null || _a === void 0 ? void 0 : _a.google),
|
|
136
162
|
},
|
|
137
163
|
});
|
|
138
164
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Serializer.js","sourceRoot":"","sources":["../../src/Serializer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAqD;AACrD,2CAA2D;AAC3D,4EAA8D;AAE9D,mC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,eAAe,CAAC;QAC3B,MAAM,cAAc,GAClB,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,cAAc,MAAK,SAAS;YAChC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,WAAW;YACjC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;QAC1B,IAAI,eAAe,EAAE;YACnB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,CAAM,CAAC;SACpE;QACD,OAAO,MAAW,CAAC;IACrB,CAAC;CACF;AAtTD,gCAsTC;AAED,kBAAe,UAAU,CAAC"}
|
package/package.json
CHANGED
package/src/Serializer.ts
CHANGED
|
@@ -10,6 +10,29 @@ import {
|
|
|
10
10
|
} from "./utils";
|
|
11
11
|
import { googleProtobufDescriptor } from "./protobuf/googleProtobufDescriptor";
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Google namespace of the types with koilib's complete copy of
|
|
15
|
+
* descriptor.proto. Contracts include descriptor.proto only because
|
|
16
|
+
* koinos/options.proto extends it, and the embedded copy can be
|
|
17
|
+
* incomplete (missing FieldDescriptorProto.Label, for instance), so
|
|
18
|
+
* its types are replaced while any other google types are kept.
|
|
19
|
+
*/
|
|
20
|
+
function withGoogleDescriptor(google?: INamespace): INamespace {
|
|
21
|
+
const descriptor = googleProtobufDescriptor.google.nested.protobuf;
|
|
22
|
+
const embedded = google?.nested?.protobuf as INamespace | undefined;
|
|
23
|
+
return {
|
|
24
|
+
...google,
|
|
25
|
+
nested: {
|
|
26
|
+
...google?.nested,
|
|
27
|
+
protobuf: {
|
|
28
|
+
...embedded,
|
|
29
|
+
...descriptor,
|
|
30
|
+
nested: { ...embedded?.nested, ...descriptor.nested },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
13
36
|
const OP_BYTES_1 = "(btype)";
|
|
14
37
|
const OP_BYTES_2 = "(koinos.btype)";
|
|
15
38
|
|
|
@@ -162,17 +185,18 @@ export class Serializer {
|
|
|
162
185
|
this.types = types;
|
|
163
186
|
if (typeof types === "string") {
|
|
164
187
|
const protos = koinosPbToProto.convert(decodeBase64(types) as Buffer);
|
|
165
|
-
this.root =
|
|
188
|
+
this.root = Root.fromJSON({ nested: googleProtobufDescriptor });
|
|
166
189
|
for (const proto of protos) {
|
|
190
|
+
// descriptor.proto is proto2 and loses its labels when converted
|
|
191
|
+
// to text, so use the copy loaded above instead
|
|
192
|
+
if (proto.file === "google/protobuf/descriptor.proto") continue;
|
|
167
193
|
parse(proto.definition, this.root, { keepCase: true });
|
|
168
194
|
}
|
|
169
195
|
} else {
|
|
170
196
|
this.root = Root.fromJSON({
|
|
171
197
|
nested: {
|
|
172
|
-
// import google protobuf descriptor if not present
|
|
173
|
-
...googleProtobufDescriptor,
|
|
174
|
-
// import types
|
|
175
198
|
...types.nested,
|
|
199
|
+
google: withGoogleDescriptor(types.nested?.google as INamespace),
|
|
176
200
|
},
|
|
177
201
|
});
|
|
178
202
|
}
|