@taquito/local-forging 22.0.0-beta.0 → 23.0.0-RC.0
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/lib/{codec-proto021.js → codec-proto022.js} +71 -23
- package/dist/lib/codec.js +87 -110
- package/dist/lib/{constants-proto021.js → constants-proto022.js} +1 -0
- package/dist/lib/constants.js +3 -0
- package/dist/lib/decoder-proto022.js +63 -0
- package/dist/lib/decoder.js +1 -0
- package/dist/lib/encoder-proto022.js +62 -0
- package/dist/lib/encoder.js +1 -0
- package/dist/lib/michelson/codec-proto022.js +283 -0
- package/dist/lib/protocols.js +2 -0
- package/dist/lib/schema/operation-proto022.js +238 -0
- package/dist/lib/schema/operation.js +11 -1
- package/dist/lib/taquito-local-forging.js +14 -8
- package/dist/lib/validator-proto022.js +56 -0
- package/dist/lib/validator.js +1 -0
- package/dist/lib/version.js +2 -2
- package/dist/taquito-local-forging.es6.js +606 -302
- package/dist/taquito-local-forging.es6.js.map +1 -1
- package/dist/taquito-local-forging.umd.js +604 -300
- package/dist/taquito-local-forging.umd.js.map +1 -1
- package/dist/types/{codec-proto021.d.ts → codec-proto022.d.ts} +3 -1
- package/dist/types/codec.d.ts +3 -3
- package/dist/types/{constants-proto021.d.ts → constants-proto022.d.ts} +1 -0
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/{decoder-proto021.d.ts → decoder-proto022.d.ts} +1 -1
- package/dist/types/{encoder-proto021.d.ts → encoder-proto022.d.ts} +1 -1
- package/dist/types/michelson/codec-proto022.d.ts +49 -0
- package/dist/types/michelson/codec.d.ts +1 -1
- package/dist/types/protocols.d.ts +1 -0
- package/dist/types/schema/{operation-proto021.d.ts → operation-proto022.d.ts} +3 -2
- package/dist/types/schema/operation.d.ts +10 -0
- package/dist/types/taquito-local-forging.d.ts +3 -3
- package/dist/types/validator-proto022.d.ts +13 -0
- package/package.json +5 -5
- package/dist/lib/decoder-proto021.js +0 -62
- package/dist/lib/encoder-proto021.js +0 -61
- package/dist/lib/schema/operation-proto021.js +0 -237
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encoders = void 0;
|
|
4
|
+
const codec_proto022_1 = require("./codec-proto022");
|
|
5
|
+
const constants_proto022_1 = require("./constants-proto022");
|
|
6
|
+
const codec_proto022_2 = require("./michelson/codec-proto022");
|
|
7
|
+
const operation_proto022_1 = require("./schema/operation-proto022");
|
|
8
|
+
exports.encoders = {
|
|
9
|
+
[constants_proto022_1.CODEC.SECRET]: (val) => val,
|
|
10
|
+
[constants_proto022_1.CODEC.RAW]: (val) => val,
|
|
11
|
+
[constants_proto022_1.CODEC.TZ1]: codec_proto022_1.tz1Encoder,
|
|
12
|
+
[constants_proto022_1.CODEC.BRANCH]: codec_proto022_1.branchEncoder,
|
|
13
|
+
[constants_proto022_1.CODEC.ZARITH]: codec_proto022_1.zarithEncoder,
|
|
14
|
+
[constants_proto022_1.CODEC.PUBLIC_KEY]: codec_proto022_1.publicKeyEncoder,
|
|
15
|
+
[constants_proto022_1.CODEC.PKH]: codec_proto022_1.publicKeyHashEncoder,
|
|
16
|
+
[constants_proto022_1.CODEC.PKH_ARR]: codec_proto022_1.publicKeyHashesEncoder,
|
|
17
|
+
[constants_proto022_1.CODEC.DELEGATE]: codec_proto022_1.delegateEncoder,
|
|
18
|
+
[constants_proto022_1.CODEC.SCRIPT]: codec_proto022_2.scriptEncoder,
|
|
19
|
+
[constants_proto022_1.CODEC.BALLOT_STATEMENT]: codec_proto022_1.ballotEncoder,
|
|
20
|
+
[constants_proto022_1.CODEC.PROPOSAL]: codec_proto022_1.proposalEncoder,
|
|
21
|
+
[constants_proto022_1.CODEC.PROPOSAL_ARR]: codec_proto022_1.proposalsEncoder,
|
|
22
|
+
[constants_proto022_1.CODEC.INT32]: codec_proto022_1.int32Encoder,
|
|
23
|
+
[constants_proto022_1.CODEC.PARAMETERS]: codec_proto022_1.parametersEncoder,
|
|
24
|
+
[constants_proto022_1.CODEC.ADDRESS]: codec_proto022_1.addressEncoder,
|
|
25
|
+
[constants_proto022_1.CODEC.SMART_ROLLUP_ADDRESS]: codec_proto022_1.smartRollupAddressEncoder,
|
|
26
|
+
[constants_proto022_1.CODEC.SMART_CONTRACT_ADDRESS]: codec_proto022_1.smartContractAddressEncoder,
|
|
27
|
+
[constants_proto022_1.CODEC.SMART_ROLLUP_COMMITMENT_HASH]: codec_proto022_1.smartRollupCommitmentHashEncoder,
|
|
28
|
+
[constants_proto022_1.CODEC.VALUE]: codec_proto022_1.valueParameterEncoder,
|
|
29
|
+
[constants_proto022_1.CODEC.INT16]: codec_proto022_1.int16Encoder,
|
|
30
|
+
[constants_proto022_1.CODEC.BLOCK_PAYLOAD_HASH]: codec_proto022_1.blockPayloadHashEncoder,
|
|
31
|
+
[constants_proto022_1.CODEC.ENTRYPOINT]: codec_proto022_1.entrypointNameEncoder,
|
|
32
|
+
[constants_proto022_1.CODEC.BURN_LIMIT]: codec_proto022_1.burnLimitEncoder,
|
|
33
|
+
[constants_proto022_1.CODEC.DEPOSITS_LIMIT]: codec_proto022_1.depositsLimitEncoder,
|
|
34
|
+
[constants_proto022_1.CODEC.SIGNATURE_PROOF]: codec_proto022_1.signatureProofEncoder,
|
|
35
|
+
[constants_proto022_1.CODEC.PVM_KIND]: codec_proto022_1.pvmKindEncoder,
|
|
36
|
+
[constants_proto022_1.CODEC.PADDED_BYTES]: codec_proto022_1.paddedBytesEncoder,
|
|
37
|
+
[constants_proto022_1.CODEC.SMART_ROLLUP_MESSAGE]: codec_proto022_1.smartRollupMessageEncoder,
|
|
38
|
+
[constants_proto022_1.CODEC.SLOT_HEADER]: codec_proto022_1.slotHeaderEncoder,
|
|
39
|
+
};
|
|
40
|
+
exports.encoders[constants_proto022_1.CODEC.OPERATION] = (0, operation_proto022_1.operationEncoder)(exports.encoders);
|
|
41
|
+
exports.encoders[constants_proto022_1.CODEC.OP_ACTIVATE_ACCOUNT] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.ActivationSchema)(val);
|
|
42
|
+
exports.encoders[constants_proto022_1.CODEC.OP_DELEGATION] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.DelegationSchema)(val);
|
|
43
|
+
exports.encoders[constants_proto022_1.CODEC.OP_TRANSACTION] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.TransactionSchema)(val);
|
|
44
|
+
exports.encoders[constants_proto022_1.CODEC.OP_ORIGINATION] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.OriginationSchema)(val);
|
|
45
|
+
exports.encoders[constants_proto022_1.CODEC.OP_BALLOT] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.BallotSchema)(val);
|
|
46
|
+
exports.encoders[constants_proto022_1.CODEC.OP_ATTESTATION] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.AttestationSchema)(val);
|
|
47
|
+
exports.encoders[constants_proto022_1.CODEC.OP_ATTESTATION_WITH_DAL] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.AttestationWithDalSchema)(val);
|
|
48
|
+
exports.encoders[constants_proto022_1.CODEC.OP_SEED_NONCE_REVELATION] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.SeedNonceRevelationSchema)(val);
|
|
49
|
+
exports.encoders[constants_proto022_1.CODEC.OP_PROPOSALS] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.ProposalsSchema)(val);
|
|
50
|
+
exports.encoders[constants_proto022_1.CODEC.OP_REVEAL] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.RevealSchema)(val);
|
|
51
|
+
exports.encoders[constants_proto022_1.CODEC.OP_REGISTER_GLOBAL_CONSTANT] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.RegisterGlobalConstantSchema)(val);
|
|
52
|
+
exports.encoders[constants_proto022_1.CODEC.OP_TRANSFER_TICKET] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.TransferTicketSchema)(val);
|
|
53
|
+
exports.encoders[constants_proto022_1.CODEC.OP_INCREASE_PAID_STORAGE] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.IncreasePaidStorageSchema)(val);
|
|
54
|
+
exports.encoders[constants_proto022_1.CODEC.OP_UPDATE_CONSENSUS_KEY] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.UpdateConsensusKeySchema)(val);
|
|
55
|
+
exports.encoders[constants_proto022_1.CODEC.OP_DRAIN_DELEGATE] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.DrainDelegateSchema)(val);
|
|
56
|
+
exports.encoders[constants_proto022_1.CODEC.OP_SMART_ROLLUP_ORIGINATE] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.SmartRollupOriginateSchema)(val);
|
|
57
|
+
exports.encoders[constants_proto022_1.CODEC.OP_SMART_ROLLUP_ADD_MESSAGES] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.SmartRollupAddMessagesSchema)(val);
|
|
58
|
+
exports.encoders[constants_proto022_1.CODEC.OP_SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.SmartRollupExecuteOutboxMessageSchema)(val);
|
|
59
|
+
exports.encoders[constants_proto022_1.CODEC.OP_DAL_PUBLISH_COMMITMENT] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.DalPublishCommitmentSchema)(val);
|
|
60
|
+
exports.encoders[constants_proto022_1.CODEC.MANAGER] = (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.ManagerOperationSchema);
|
|
61
|
+
exports.encoders[constants_proto022_1.CODEC.OP_SET_DEPOSITS_LIMIT] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.SetDepositsLimitSchema)(val);
|
|
62
|
+
exports.encoders[constants_proto022_1.CODEC.OP_FAILING_NOOP] = (val) => (0, operation_proto022_1.schemaEncoder)(exports.encoders)(operation_proto022_1.FailingNoopSchema)(val);
|
package/dist/lib/encoder.js
CHANGED
|
@@ -52,6 +52,7 @@ exports.encoders[constants_1.CODEC.OP_REGISTER_GLOBAL_CONSTANT] = (val) => (0, o
|
|
|
52
52
|
exports.encoders[constants_1.CODEC.OP_TRANSFER_TICKET] = (val) => (0, operation_1.schemaEncoder)(exports.encoders)(operation_1.TransferTicketSchema)(val);
|
|
53
53
|
exports.encoders[constants_1.CODEC.OP_INCREASE_PAID_STORAGE] = (val) => (0, operation_1.schemaEncoder)(exports.encoders)(operation_1.IncreasePaidStorageSchema)(val);
|
|
54
54
|
exports.encoders[constants_1.CODEC.OP_UPDATE_CONSENSUS_KEY] = (val) => (0, operation_1.schemaEncoder)(exports.encoders)(operation_1.UpdateConsensusKeySchema)(val);
|
|
55
|
+
exports.encoders[constants_1.CODEC.OP_UPDATE_COMPANION_KEY] = (val) => (0, operation_1.schemaEncoder)(exports.encoders)(operation_1.UpdateCompanionKeySchema)(val);
|
|
55
56
|
exports.encoders[constants_1.CODEC.OP_DRAIN_DELEGATE] = (val) => (0, operation_1.schemaEncoder)(exports.encoders)(operation_1.DrainDelegateSchema)(val);
|
|
56
57
|
exports.encoders[constants_1.CODEC.OP_SMART_ROLLUP_ORIGINATE] = (val) => (0, operation_1.schemaEncoder)(exports.encoders)(operation_1.SmartRollupOriginateSchema)(val);
|
|
57
58
|
exports.encoders[constants_1.CODEC.OP_SMART_ROLLUP_ADD_MESSAGES] = (val) => (0, operation_1.schemaEncoder)(exports.encoders)(operation_1.SmartRollupAddMessagesSchema)(val);
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeAnnots = exports.encodeAnnots = exports.decodeCombPair = exports.primViewDecoder = exports.primDecoder = exports.primEncoder = exports.intDecoder = exports.intEncoder = exports.stringDecoder = exports.stringEncoder = exports.bytesDecoder = exports.bytesEncoder = exports.stripLengthPrefixFromBytes = exports.extractRequiredLen = exports.valueDecoder = exports.valueEncoder = exports.scriptDecoder = exports.scriptEncoder = exports.isInt = exports.isString = exports.isBytes = exports.isPrim = void 0;
|
|
4
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
5
|
+
const uint8array_consumer_1 = require("../uint8array-consumer");
|
|
6
|
+
const constants_proto022_1 = require("../constants-proto022");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const errors_1 = require("../errors");
|
|
9
|
+
const core_1 = require("@taquito/core");
|
|
10
|
+
const isPrim = (value) => {
|
|
11
|
+
return 'prim' in value;
|
|
12
|
+
};
|
|
13
|
+
exports.isPrim = isPrim;
|
|
14
|
+
const isBytes = (value) => {
|
|
15
|
+
return 'bytes' in value && typeof value.bytes === 'string';
|
|
16
|
+
};
|
|
17
|
+
exports.isBytes = isBytes;
|
|
18
|
+
const isString = (value) => {
|
|
19
|
+
return 'string' in value && typeof value.string === 'string';
|
|
20
|
+
};
|
|
21
|
+
exports.isString = isString;
|
|
22
|
+
const isInt = (value) => {
|
|
23
|
+
return 'int' in value && typeof value.int === 'string';
|
|
24
|
+
};
|
|
25
|
+
exports.isInt = isInt;
|
|
26
|
+
const scriptEncoder = (script) => {
|
|
27
|
+
const code = (0, exports.valueEncoder)(script.code);
|
|
28
|
+
const storage = (0, exports.valueEncoder)(script.storage);
|
|
29
|
+
return `${(0, utils_1.pad)(code.length / 2, 8)}${code}${(0, utils_1.pad)(storage.length / 2, 8)}${storage}`;
|
|
30
|
+
};
|
|
31
|
+
exports.scriptEncoder = scriptEncoder;
|
|
32
|
+
const scriptDecoder = (value) => {
|
|
33
|
+
const code = (0, exports.extractRequiredLen)(value);
|
|
34
|
+
const storage = (0, exports.extractRequiredLen)(value);
|
|
35
|
+
return {
|
|
36
|
+
code: (0, exports.valueDecoder)(new uint8array_consumer_1.Uint8ArrayConsumer(code)),
|
|
37
|
+
storage: (0, exports.valueDecoder)(new uint8array_consumer_1.Uint8ArrayConsumer(storage)),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
exports.scriptDecoder = scriptDecoder;
|
|
41
|
+
const valueEncoder = (value) => {
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
const encoded = value.map((x) => (0, exports.valueEncoder)(x)).join('');
|
|
44
|
+
const len = encoded.length / 2;
|
|
45
|
+
return `02${(0, utils_1.pad)(len)}${encoded}`;
|
|
46
|
+
}
|
|
47
|
+
else if ((0, exports.isPrim)(value)) {
|
|
48
|
+
return (0, exports.primEncoder)(value);
|
|
49
|
+
}
|
|
50
|
+
else if ((0, exports.isBytes)(value)) {
|
|
51
|
+
return (0, exports.bytesEncoder)(value);
|
|
52
|
+
}
|
|
53
|
+
else if ((0, exports.isString)(value)) {
|
|
54
|
+
return (0, exports.stringEncoder)(value);
|
|
55
|
+
}
|
|
56
|
+
else if ((0, exports.isInt)(value)) {
|
|
57
|
+
return (0, exports.intEncoder)(value);
|
|
58
|
+
}
|
|
59
|
+
throw new errors_1.UnexpectedMichelsonValueError(JSON.stringify(value));
|
|
60
|
+
};
|
|
61
|
+
exports.valueEncoder = valueEncoder;
|
|
62
|
+
const valueDecoder = (value) => {
|
|
63
|
+
const preamble = value.consume(1);
|
|
64
|
+
switch (preamble[0]) {
|
|
65
|
+
case 0x0a:
|
|
66
|
+
return (0, exports.bytesDecoder)(value);
|
|
67
|
+
case 0x01:
|
|
68
|
+
return (0, exports.stringDecoder)(value);
|
|
69
|
+
case 0x00:
|
|
70
|
+
return (0, exports.intDecoder)(value);
|
|
71
|
+
case 0x02: {
|
|
72
|
+
const val = new uint8array_consumer_1.Uint8ArrayConsumer((0, exports.extractRequiredLen)(value));
|
|
73
|
+
const results = [];
|
|
74
|
+
while (val.length() > 0) {
|
|
75
|
+
results.push((0, exports.valueDecoder)(val));
|
|
76
|
+
}
|
|
77
|
+
return results;
|
|
78
|
+
}
|
|
79
|
+
default:
|
|
80
|
+
return (0, exports.primDecoder)(value, preamble);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
exports.valueDecoder = valueDecoder;
|
|
84
|
+
const extractRequiredLen = (value, bytesLength = 4) => {
|
|
85
|
+
const len = value.consume(bytesLength);
|
|
86
|
+
const valueLen = parseInt(Buffer.from(len).toString('hex'), 16);
|
|
87
|
+
return value.consume(valueLen);
|
|
88
|
+
};
|
|
89
|
+
exports.extractRequiredLen = extractRequiredLen;
|
|
90
|
+
/**
|
|
91
|
+
* @description parse bytes into multiple items of an array
|
|
92
|
+
* @param value Uint8ArrayConsumer class of forged segment to parse
|
|
93
|
+
* @param bytesLength default 4 bytes for length of variable bytes
|
|
94
|
+
* @returns array of Uint8Array values for each array item
|
|
95
|
+
*/
|
|
96
|
+
const stripLengthPrefixFromBytes = (value, bytesLength = 4) => {
|
|
97
|
+
const ret = [];
|
|
98
|
+
let values = value;
|
|
99
|
+
while (values.length()) {
|
|
100
|
+
const len = values.consume(bytesLength);
|
|
101
|
+
const valueLen = parseInt(Buffer.from(len).toString('hex'), 16);
|
|
102
|
+
ret.push(values.consume(valueLen));
|
|
103
|
+
values = values.slice(valueLen + bytesLength);
|
|
104
|
+
}
|
|
105
|
+
return ret;
|
|
106
|
+
};
|
|
107
|
+
exports.stripLengthPrefixFromBytes = stripLengthPrefixFromBytes;
|
|
108
|
+
const bytesEncoder = (value) => {
|
|
109
|
+
if (!/^([A-Fa-f0-9]{2})*$/.test(value.bytes)) {
|
|
110
|
+
throw new core_1.InvalidHexStringError(value.bytes);
|
|
111
|
+
}
|
|
112
|
+
const len = value.bytes.length / 2;
|
|
113
|
+
return `0a${(0, utils_1.pad)(len)}${value.bytes}`;
|
|
114
|
+
};
|
|
115
|
+
exports.bytesEncoder = bytesEncoder;
|
|
116
|
+
const bytesDecoder = (value) => {
|
|
117
|
+
const bytes = (0, exports.extractRequiredLen)(value);
|
|
118
|
+
return {
|
|
119
|
+
bytes: Buffer.from(bytes).toString('hex'),
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
exports.bytesDecoder = bytesDecoder;
|
|
123
|
+
const stringEncoder = (value) => {
|
|
124
|
+
const str = Buffer.from(value.string, 'utf8').toString('hex');
|
|
125
|
+
const hexLength = str.length / 2;
|
|
126
|
+
return `01${(0, utils_1.pad)(hexLength)}${str}`;
|
|
127
|
+
};
|
|
128
|
+
exports.stringEncoder = stringEncoder;
|
|
129
|
+
const stringDecoder = (value) => {
|
|
130
|
+
const str = (0, exports.extractRequiredLen)(value);
|
|
131
|
+
return {
|
|
132
|
+
string: Buffer.from(str).toString('utf8'),
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
exports.stringDecoder = stringDecoder;
|
|
136
|
+
const intEncoder = ({ int }) => {
|
|
137
|
+
const num = new bignumber_js_1.BigNumber(int, 10);
|
|
138
|
+
const positiveMark = num.toString(2)[0] === '-' ? '1' : '0';
|
|
139
|
+
const binary = num.toString(2).replace(/-/g, '');
|
|
140
|
+
const pad = binary.length <= 6
|
|
141
|
+
? 6
|
|
142
|
+
: (binary.length - 6) % 7
|
|
143
|
+
? binary.length + 7 - ((binary.length - 6) % 7)
|
|
144
|
+
: binary.length;
|
|
145
|
+
const splitted = binary.padStart(pad, '0').match(/\d{6,7}/g);
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
147
|
+
const reversed = splitted.reverse();
|
|
148
|
+
reversed[0] = positiveMark + reversed[0];
|
|
149
|
+
const numHex = reversed.map((x, i) =>
|
|
150
|
+
// Add one to the last chunk
|
|
151
|
+
parseInt((i === reversed.length - 1 ? '0' : '1') + x, 2)
|
|
152
|
+
.toString(16)
|
|
153
|
+
.padStart(2, '0'));
|
|
154
|
+
return `00${numHex.join('')}`;
|
|
155
|
+
};
|
|
156
|
+
exports.intEncoder = intEncoder;
|
|
157
|
+
const intDecoder = (value) => {
|
|
158
|
+
let c = value.consume(1)[0];
|
|
159
|
+
const hexNumber = [];
|
|
160
|
+
const isNotLastChunkMask = 1 << 7;
|
|
161
|
+
while (c & isNotLastChunkMask) {
|
|
162
|
+
hexNumber.push(c);
|
|
163
|
+
c = value.consume(1)[0];
|
|
164
|
+
}
|
|
165
|
+
hexNumber.push(c);
|
|
166
|
+
const isNegative = !!((1 << 6) & hexNumber[0]);
|
|
167
|
+
hexNumber[0] = hexNumber[0] & 0b1111111;
|
|
168
|
+
const numBin = hexNumber
|
|
169
|
+
.map((x, i) => x
|
|
170
|
+
.toString(2)
|
|
171
|
+
.slice(i === 0 ? -6 : -7)
|
|
172
|
+
.padStart(i === 0 ? 6 : 7, '0'))
|
|
173
|
+
.reverse();
|
|
174
|
+
let num = new bignumber_js_1.BigNumber(numBin.join(''), 2);
|
|
175
|
+
if (isNegative) {
|
|
176
|
+
num = num.times(-1);
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
int: num.toFixed(),
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
exports.intDecoder = intDecoder;
|
|
183
|
+
const primEncoder = (value) => {
|
|
184
|
+
const hasAnnot = +Array.isArray(value.annots);
|
|
185
|
+
const argsCount = Array.isArray(value.args) ? value.args.length : 0;
|
|
186
|
+
// Specify the number of args max is 3 without annotation
|
|
187
|
+
const preamble = (0, utils_1.pad)(Math.min(2 * argsCount + hasAnnot + 0x03, 9), 2);
|
|
188
|
+
const op = constants_proto022_1.opMappingReverse[value.prim];
|
|
189
|
+
let encodedArgs = (value.args || []).map((arg) => (0, exports.valueEncoder)(arg)).join('');
|
|
190
|
+
const encodedAnnots = Array.isArray(value.annots) ? (0, exports.encodeAnnots)(value.annots) : '';
|
|
191
|
+
if ((value.prim === 'LAMBDA' || value.prim === 'LAMBDA_REC') && argsCount) {
|
|
192
|
+
encodedArgs = (0, utils_1.pad)(encodedArgs.length / 2) + encodedArgs + (0, utils_1.pad)(0);
|
|
193
|
+
}
|
|
194
|
+
if ((value.prim === 'pair' || value.prim === 'Pair') && argsCount > 2) {
|
|
195
|
+
encodedArgs =
|
|
196
|
+
encodedAnnots === ''
|
|
197
|
+
? (0, utils_1.pad)(encodedArgs.length / 2) + encodedArgs + (0, utils_1.pad)(0)
|
|
198
|
+
: (0, utils_1.pad)(encodedArgs.length / 2) + encodedArgs;
|
|
199
|
+
}
|
|
200
|
+
if (value.prim === 'view' && value.args) {
|
|
201
|
+
encodedArgs = (0, utils_1.pad)(encodedArgs.length / 2) + encodedArgs + (0, utils_1.pad)(0);
|
|
202
|
+
}
|
|
203
|
+
return `${preamble}${op}${encodedArgs}${encodedAnnots}`;
|
|
204
|
+
};
|
|
205
|
+
exports.primEncoder = primEncoder;
|
|
206
|
+
const primDecoder = (value, preamble) => {
|
|
207
|
+
const hasAnnot = (preamble[0] - 0x03) % 2 === 1;
|
|
208
|
+
let argsCount = Math.floor((preamble[0] - 0x03) / 2);
|
|
209
|
+
const op = value.consume(1)[0].toString(16).padStart(2, '0');
|
|
210
|
+
const result = {
|
|
211
|
+
prim: constants_proto022_1.opMapping[op],
|
|
212
|
+
};
|
|
213
|
+
if (constants_proto022_1.opMapping[op] === 'LAMBDA' || constants_proto022_1.opMapping[op] === 'LAMBDA_REC') {
|
|
214
|
+
value.consume(4);
|
|
215
|
+
}
|
|
216
|
+
if (constants_proto022_1.opMapping[op] === 'view') {
|
|
217
|
+
if (argsCount != 0) {
|
|
218
|
+
return (0, exports.primViewDecoder)(value, result);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
let combPairArgs;
|
|
225
|
+
let combPairAnnots;
|
|
226
|
+
if ((constants_proto022_1.opMapping[op] === 'pair' || constants_proto022_1.opMapping[op] === 'Pair') && argsCount > 2) {
|
|
227
|
+
combPairArgs = (0, exports.decodeCombPair)(value);
|
|
228
|
+
argsCount = 0;
|
|
229
|
+
combPairAnnots = (0, exports.decodeAnnots)(value);
|
|
230
|
+
}
|
|
231
|
+
const args = new Array(argsCount).fill(0).map(() => (0, exports.valueDecoder)(value));
|
|
232
|
+
if (constants_proto022_1.opMapping[op] === 'LAMBDA' || constants_proto022_1.opMapping[op] === 'LAMBDA_REC') {
|
|
233
|
+
value.consume(4);
|
|
234
|
+
}
|
|
235
|
+
if (combPairArgs) {
|
|
236
|
+
result['args'] = combPairArgs;
|
|
237
|
+
}
|
|
238
|
+
else if (args.length) {
|
|
239
|
+
result['args'] = args;
|
|
240
|
+
}
|
|
241
|
+
if (combPairAnnots && combPairAnnots[0] !== '') {
|
|
242
|
+
result['annots'] = combPairAnnots;
|
|
243
|
+
}
|
|
244
|
+
else if (hasAnnot) {
|
|
245
|
+
result['annots'] = (0, exports.decodeAnnots)(value);
|
|
246
|
+
}
|
|
247
|
+
return result;
|
|
248
|
+
};
|
|
249
|
+
exports.primDecoder = primDecoder;
|
|
250
|
+
const primViewDecoder = (value, result) => {
|
|
251
|
+
value.consume(4);
|
|
252
|
+
result['args'] = new Array(4).fill(0).map(() => (0, exports.valueDecoder)(value));
|
|
253
|
+
value.consume(4);
|
|
254
|
+
return result;
|
|
255
|
+
};
|
|
256
|
+
exports.primViewDecoder = primViewDecoder;
|
|
257
|
+
const decodeCombPair = (val) => {
|
|
258
|
+
const array = new uint8array_consumer_1.Uint8ArrayConsumer((0, exports.extractRequiredLen)(val));
|
|
259
|
+
const args = [];
|
|
260
|
+
while (array.length() > 0) {
|
|
261
|
+
args.push((0, exports.valueDecoder)(array));
|
|
262
|
+
}
|
|
263
|
+
return args;
|
|
264
|
+
};
|
|
265
|
+
exports.decodeCombPair = decodeCombPair;
|
|
266
|
+
const encodeAnnots = (value) => {
|
|
267
|
+
const mergedAnnot = value
|
|
268
|
+
.map((x) => {
|
|
269
|
+
return Buffer.from(x, 'utf8').toString('hex');
|
|
270
|
+
})
|
|
271
|
+
.join('20');
|
|
272
|
+
const len = mergedAnnot.length / 2;
|
|
273
|
+
return `${(0, utils_1.pad)(len)}${mergedAnnot}`;
|
|
274
|
+
};
|
|
275
|
+
exports.encodeAnnots = encodeAnnots;
|
|
276
|
+
const decodeAnnots = (val) => {
|
|
277
|
+
const len = val.consume(4);
|
|
278
|
+
const annotLen = parseInt(Buffer.from(len).toString('hex'), 16);
|
|
279
|
+
const restOfAnnot = val.consume(annotLen);
|
|
280
|
+
const restOfAnnotHex = Buffer.from(restOfAnnot).toString('hex');
|
|
281
|
+
return restOfAnnotHex.split('20').map((x) => Buffer.from(x, 'hex').toString('utf8'));
|
|
282
|
+
};
|
|
283
|
+
exports.decodeAnnots = decodeAnnots;
|
package/dist/lib/protocols.js
CHANGED
|
@@ -25,6 +25,7 @@ var ProtocolsHash;
|
|
|
25
25
|
ProtocolsHash["PsParisCZ"] = "PsParisCZo7KAh1Z1smVd9ZMZ1HHn5gkzbM94V3PLCpknFWhUAi";
|
|
26
26
|
ProtocolsHash["PsQuebecn"] = "PsQuebecnLByd3JwTiGadoG4nGWi3HYiLXUjkibeFV8dCFeVMUg";
|
|
27
27
|
ProtocolsHash["PsRiotuma"] = "PsRiotumaAMotcRoDWW1bysEhQy2n1M5fy8JgRp8jjRfHGmfeA7";
|
|
28
|
+
ProtocolsHash["PtSeouLou"] = "PtSeouLouXkxhg39oWzjxDWaCydNfR3RxCUrNe4Q9Ro8BTehcbh";
|
|
28
29
|
ProtocolsHash["ProtoALpha"] = "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK";
|
|
29
30
|
})(ProtocolsHash || (exports.ProtocolsHash = ProtocolsHash = {}));
|
|
30
31
|
const protoLevel = {
|
|
@@ -49,6 +50,7 @@ const protoLevel = {
|
|
|
49
50
|
PsParisCZo7KAh1Z1smVd9ZMZ1HHn5gkzbM94V3PLCpknFWhUAi: 20,
|
|
50
51
|
PsQuebecnLByd3JwTiGadoG4nGWi3HYiLXUjkibeFV8dCFeVMUg: 21,
|
|
51
52
|
PsRiotumaAMotcRoDWW1bysEhQy2n1M5fy8JgRp8jjRfHGmfeA7: 22,
|
|
53
|
+
PtSeouLouXkxhg39oWzjxDWaCydNfR3RxCUrNe4Q9Ro8BTehcbh: 23,
|
|
52
54
|
ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK: 23,
|
|
53
55
|
};
|
|
54
56
|
function ProtoInferiorTo(a, b) {
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schemaDecoder = exports.schemaEncoder = exports.operationDecoder = exports.operationEncoder = exports.FailingNoopSchema = exports.DalPublishCommitmentSchema = exports.SmartRollupExecuteOutboxMessageSchema = exports.SmartRollupAddMessagesSchema = exports.SmartRollupOriginateSchema = exports.SetDepositsLimitSchema = exports.DrainDelegateSchema = exports.UpdateConsensusKeySchema = exports.IncreasePaidStorageSchema = exports.TransferTicketSchema = exports.RegisterGlobalConstantSchema = exports.ProposalsSchema = exports.SeedNonceRevelationSchema = exports.AttestationWithDalSchema = exports.AttestationSchema = exports.BallotSchema = exports.OriginationSchema = exports.TransactionSchema = exports.DelegationSchema = exports.RevealSchema = exports.ActivationSchema = exports.ManagerOperationSchema = void 0;
|
|
4
|
+
const constants_proto022_1 = require("../constants-proto022");
|
|
5
|
+
const core_1 = require("@taquito/core");
|
|
6
|
+
const errors_1 = require("../errors");
|
|
7
|
+
exports.ManagerOperationSchema = {
|
|
8
|
+
branch: constants_proto022_1.CODEC.BRANCH,
|
|
9
|
+
contents: [constants_proto022_1.CODEC.OPERATION],
|
|
10
|
+
};
|
|
11
|
+
exports.ActivationSchema = {
|
|
12
|
+
pkh: constants_proto022_1.CODEC.TZ1,
|
|
13
|
+
secret: constants_proto022_1.CODEC.SECRET,
|
|
14
|
+
};
|
|
15
|
+
exports.RevealSchema = {
|
|
16
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
17
|
+
fee: constants_proto022_1.CODEC.ZARITH,
|
|
18
|
+
counter: constants_proto022_1.CODEC.ZARITH,
|
|
19
|
+
gas_limit: constants_proto022_1.CODEC.ZARITH,
|
|
20
|
+
storage_limit: constants_proto022_1.CODEC.ZARITH,
|
|
21
|
+
public_key: constants_proto022_1.CODEC.PUBLIC_KEY,
|
|
22
|
+
};
|
|
23
|
+
exports.DelegationSchema = {
|
|
24
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
25
|
+
fee: constants_proto022_1.CODEC.ZARITH,
|
|
26
|
+
counter: constants_proto022_1.CODEC.ZARITH,
|
|
27
|
+
gas_limit: constants_proto022_1.CODEC.ZARITH,
|
|
28
|
+
storage_limit: constants_proto022_1.CODEC.ZARITH,
|
|
29
|
+
delegate: constants_proto022_1.CODEC.DELEGATE,
|
|
30
|
+
};
|
|
31
|
+
exports.TransactionSchema = {
|
|
32
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
33
|
+
fee: constants_proto022_1.CODEC.ZARITH,
|
|
34
|
+
counter: constants_proto022_1.CODEC.ZARITH,
|
|
35
|
+
gas_limit: constants_proto022_1.CODEC.ZARITH,
|
|
36
|
+
storage_limit: constants_proto022_1.CODEC.ZARITH,
|
|
37
|
+
amount: constants_proto022_1.CODEC.ZARITH,
|
|
38
|
+
destination: constants_proto022_1.CODEC.ADDRESS,
|
|
39
|
+
parameters: constants_proto022_1.CODEC.PARAMETERS,
|
|
40
|
+
};
|
|
41
|
+
exports.OriginationSchema = {
|
|
42
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
43
|
+
fee: constants_proto022_1.CODEC.ZARITH,
|
|
44
|
+
counter: constants_proto022_1.CODEC.ZARITH,
|
|
45
|
+
gas_limit: constants_proto022_1.CODEC.ZARITH,
|
|
46
|
+
storage_limit: constants_proto022_1.CODEC.ZARITH,
|
|
47
|
+
balance: constants_proto022_1.CODEC.ZARITH,
|
|
48
|
+
delegate: constants_proto022_1.CODEC.DELEGATE,
|
|
49
|
+
script: constants_proto022_1.CODEC.SCRIPT,
|
|
50
|
+
};
|
|
51
|
+
exports.BallotSchema = {
|
|
52
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
53
|
+
period: constants_proto022_1.CODEC.INT32,
|
|
54
|
+
proposal: constants_proto022_1.CODEC.PROPOSAL,
|
|
55
|
+
ballot: constants_proto022_1.CODEC.BALLOT_STATEMENT,
|
|
56
|
+
};
|
|
57
|
+
exports.AttestationSchema = {
|
|
58
|
+
slot: constants_proto022_1.CODEC.INT16,
|
|
59
|
+
level: constants_proto022_1.CODEC.INT32,
|
|
60
|
+
round: constants_proto022_1.CODEC.INT32,
|
|
61
|
+
block_payload_hash: constants_proto022_1.CODEC.BLOCK_PAYLOAD_HASH,
|
|
62
|
+
};
|
|
63
|
+
exports.AttestationWithDalSchema = {
|
|
64
|
+
slot: constants_proto022_1.CODEC.INT16,
|
|
65
|
+
level: constants_proto022_1.CODEC.INT32,
|
|
66
|
+
round: constants_proto022_1.CODEC.INT32,
|
|
67
|
+
block_payload_hash: constants_proto022_1.CODEC.BLOCK_PAYLOAD_HASH,
|
|
68
|
+
dal_attestation: constants_proto022_1.CODEC.ZARITH,
|
|
69
|
+
};
|
|
70
|
+
exports.SeedNonceRevelationSchema = {
|
|
71
|
+
level: constants_proto022_1.CODEC.INT32,
|
|
72
|
+
nonce: constants_proto022_1.CODEC.RAW,
|
|
73
|
+
};
|
|
74
|
+
exports.ProposalsSchema = {
|
|
75
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
76
|
+
period: constants_proto022_1.CODEC.INT32,
|
|
77
|
+
proposals: constants_proto022_1.CODEC.PROPOSAL_ARR,
|
|
78
|
+
};
|
|
79
|
+
exports.RegisterGlobalConstantSchema = {
|
|
80
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
81
|
+
fee: constants_proto022_1.CODEC.ZARITH,
|
|
82
|
+
counter: constants_proto022_1.CODEC.ZARITH,
|
|
83
|
+
gas_limit: constants_proto022_1.CODEC.ZARITH,
|
|
84
|
+
storage_limit: constants_proto022_1.CODEC.ZARITH,
|
|
85
|
+
value: constants_proto022_1.CODEC.VALUE,
|
|
86
|
+
};
|
|
87
|
+
exports.TransferTicketSchema = {
|
|
88
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
89
|
+
fee: constants_proto022_1.CODEC.ZARITH,
|
|
90
|
+
counter: constants_proto022_1.CODEC.ZARITH,
|
|
91
|
+
gas_limit: constants_proto022_1.CODEC.ZARITH,
|
|
92
|
+
storage_limit: constants_proto022_1.CODEC.ZARITH,
|
|
93
|
+
ticket_contents: constants_proto022_1.CODEC.VALUE,
|
|
94
|
+
ticket_ty: constants_proto022_1.CODEC.VALUE,
|
|
95
|
+
ticket_ticketer: constants_proto022_1.CODEC.ADDRESS,
|
|
96
|
+
ticket_amount: constants_proto022_1.CODEC.ZARITH,
|
|
97
|
+
destination: constants_proto022_1.CODEC.ADDRESS,
|
|
98
|
+
entrypoint: constants_proto022_1.CODEC.ENTRYPOINT,
|
|
99
|
+
};
|
|
100
|
+
exports.IncreasePaidStorageSchema = {
|
|
101
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
102
|
+
fee: constants_proto022_1.CODEC.ZARITH,
|
|
103
|
+
counter: constants_proto022_1.CODEC.ZARITH,
|
|
104
|
+
gas_limit: constants_proto022_1.CODEC.ZARITH,
|
|
105
|
+
storage_limit: constants_proto022_1.CODEC.ZARITH,
|
|
106
|
+
amount: constants_proto022_1.CODEC.ZARITH,
|
|
107
|
+
destination: constants_proto022_1.CODEC.SMART_CONTRACT_ADDRESS,
|
|
108
|
+
};
|
|
109
|
+
exports.UpdateConsensusKeySchema = {
|
|
110
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
111
|
+
fee: constants_proto022_1.CODEC.ZARITH,
|
|
112
|
+
counter: constants_proto022_1.CODEC.ZARITH,
|
|
113
|
+
gas_limit: constants_proto022_1.CODEC.ZARITH,
|
|
114
|
+
storage_limit: constants_proto022_1.CODEC.ZARITH,
|
|
115
|
+
pk: constants_proto022_1.CODEC.PUBLIC_KEY,
|
|
116
|
+
proof: constants_proto022_1.CODEC.SIGNATURE_PROOF,
|
|
117
|
+
};
|
|
118
|
+
exports.DrainDelegateSchema = {
|
|
119
|
+
consensus_key: constants_proto022_1.CODEC.PKH,
|
|
120
|
+
delegate: constants_proto022_1.CODEC.PKH,
|
|
121
|
+
destination: constants_proto022_1.CODEC.PKH,
|
|
122
|
+
};
|
|
123
|
+
exports.SetDepositsLimitSchema = {
|
|
124
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
125
|
+
fee: constants_proto022_1.CODEC.ZARITH,
|
|
126
|
+
counter: constants_proto022_1.CODEC.ZARITH,
|
|
127
|
+
gas_limit: constants_proto022_1.CODEC.ZARITH,
|
|
128
|
+
storage_limit: constants_proto022_1.CODEC.ZARITH,
|
|
129
|
+
limit: constants_proto022_1.CODEC.DEPOSITS_LIMIT,
|
|
130
|
+
};
|
|
131
|
+
exports.SmartRollupOriginateSchema = {
|
|
132
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
133
|
+
fee: constants_proto022_1.CODEC.ZARITH,
|
|
134
|
+
counter: constants_proto022_1.CODEC.ZARITH,
|
|
135
|
+
gas_limit: constants_proto022_1.CODEC.ZARITH,
|
|
136
|
+
storage_limit: constants_proto022_1.CODEC.ZARITH,
|
|
137
|
+
pvm_kind: constants_proto022_1.CODEC.PVM_KIND,
|
|
138
|
+
kernel: constants_proto022_1.CODEC.PADDED_BYTES,
|
|
139
|
+
parameters_ty: constants_proto022_1.CODEC.VALUE,
|
|
140
|
+
whitelist: constants_proto022_1.CODEC.PKH_ARR,
|
|
141
|
+
};
|
|
142
|
+
exports.SmartRollupAddMessagesSchema = {
|
|
143
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
144
|
+
fee: constants_proto022_1.CODEC.ZARITH,
|
|
145
|
+
counter: constants_proto022_1.CODEC.ZARITH,
|
|
146
|
+
gas_limit: constants_proto022_1.CODEC.ZARITH,
|
|
147
|
+
storage_limit: constants_proto022_1.CODEC.ZARITH,
|
|
148
|
+
message: constants_proto022_1.CODEC.SMART_ROLLUP_MESSAGE,
|
|
149
|
+
};
|
|
150
|
+
exports.SmartRollupExecuteOutboxMessageSchema = {
|
|
151
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
152
|
+
fee: constants_proto022_1.CODEC.ZARITH,
|
|
153
|
+
counter: constants_proto022_1.CODEC.ZARITH,
|
|
154
|
+
gas_limit: constants_proto022_1.CODEC.ZARITH,
|
|
155
|
+
storage_limit: constants_proto022_1.CODEC.ZARITH,
|
|
156
|
+
rollup: constants_proto022_1.CODEC.SMART_ROLLUP_ADDRESS,
|
|
157
|
+
cemented_commitment: constants_proto022_1.CODEC.SMART_ROLLUP_COMMITMENT_HASH,
|
|
158
|
+
output_proof: constants_proto022_1.CODEC.PADDED_BYTES,
|
|
159
|
+
};
|
|
160
|
+
exports.DalPublishCommitmentSchema = {
|
|
161
|
+
source: constants_proto022_1.CODEC.PKH,
|
|
162
|
+
fee: constants_proto022_1.CODEC.ZARITH,
|
|
163
|
+
counter: constants_proto022_1.CODEC.ZARITH,
|
|
164
|
+
gas_limit: constants_proto022_1.CODEC.ZARITH,
|
|
165
|
+
storage_limit: constants_proto022_1.CODEC.ZARITH,
|
|
166
|
+
slot_header: constants_proto022_1.CODEC.SLOT_HEADER,
|
|
167
|
+
};
|
|
168
|
+
exports.FailingNoopSchema = {
|
|
169
|
+
arbitrary: constants_proto022_1.CODEC.PADDED_BYTES,
|
|
170
|
+
};
|
|
171
|
+
const operationEncoder = (encoders) => (operation) => {
|
|
172
|
+
if (!(operation.kind in encoders) || !(operation.kind in constants_proto022_1.kindMappingReverse)) {
|
|
173
|
+
throw new core_1.InvalidOperationKindError(operation.kind);
|
|
174
|
+
}
|
|
175
|
+
return constants_proto022_1.kindMappingReverse[operation.kind] + encoders[operation.kind](operation);
|
|
176
|
+
};
|
|
177
|
+
exports.operationEncoder = operationEncoder;
|
|
178
|
+
const operationDecoder = (decoders) => (value) => {
|
|
179
|
+
const op = value.consume(1);
|
|
180
|
+
const operationName = constants_proto022_1.kindMapping[op[0]];
|
|
181
|
+
if (operationName === undefined) {
|
|
182
|
+
throw new errors_1.UnsupportedOperationError(op[0].toString());
|
|
183
|
+
}
|
|
184
|
+
const decodedObj = decoders[operationName](value);
|
|
185
|
+
if (typeof decodedObj !== 'object') {
|
|
186
|
+
throw new errors_1.OperationDecodingError('Invalid operation, cannot be decoded.');
|
|
187
|
+
}
|
|
188
|
+
return Object.assign({ kind: operationName }, decodedObj);
|
|
189
|
+
};
|
|
190
|
+
exports.operationDecoder = operationDecoder;
|
|
191
|
+
const schemaEncoder = (encoders) => (schema) => (value) => {
|
|
192
|
+
const keys = Object.keys(schema);
|
|
193
|
+
return keys.reduce((prev, key) => {
|
|
194
|
+
const valueToEncode = schema[key];
|
|
195
|
+
if (value && Array.isArray(valueToEncode)) {
|
|
196
|
+
const encoder = encoders[valueToEncode[0]];
|
|
197
|
+
const values = value[key];
|
|
198
|
+
if (!Array.isArray(values)) {
|
|
199
|
+
throw new errors_1.OperationEncodingError(`Invalid operation value "${JSON.stringify(values)}" of key "${key}, expected value to be Array.`);
|
|
200
|
+
}
|
|
201
|
+
return (prev + values.reduce((prevBytes, current) => prevBytes + encoder(current), ''));
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
const encoder = encoders[valueToEncode];
|
|
205
|
+
return prev + encoder(value[key]);
|
|
206
|
+
}
|
|
207
|
+
}, '');
|
|
208
|
+
};
|
|
209
|
+
exports.schemaEncoder = schemaEncoder;
|
|
210
|
+
const schemaDecoder = (decoders) => (schema) => (value) => {
|
|
211
|
+
const keys = Object.keys(schema);
|
|
212
|
+
return keys.reduce((prev, key) => {
|
|
213
|
+
const valueToEncode = schema[key];
|
|
214
|
+
if (Array.isArray(valueToEncode)) {
|
|
215
|
+
const decoder = decoders[valueToEncode[0]];
|
|
216
|
+
const decoded = [];
|
|
217
|
+
const lastLength = value.length();
|
|
218
|
+
while (value.length() > 0) {
|
|
219
|
+
decoded.push(decoder(value));
|
|
220
|
+
if (lastLength === value.length()) {
|
|
221
|
+
throw new errors_1.OperationDecodingError('Unable to decode value');
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return Object.assign(Object.assign({}, prev), { [key]: decoded });
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
const decoder = decoders[valueToEncode];
|
|
228
|
+
const result = decoder(value);
|
|
229
|
+
if (typeof result !== 'undefined') {
|
|
230
|
+
return Object.assign(Object.assign({}, prev), { [key]: result });
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
return Object.assign({}, prev);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}, {});
|
|
237
|
+
};
|
|
238
|
+
exports.schemaDecoder = schemaDecoder;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.schemaDecoder = exports.schemaEncoder = exports.operationDecoder = exports.operationEncoder = exports.FailingNoopSchema = exports.DalPublishCommitmentSchema = exports.SmartRollupExecuteOutboxMessageSchema = exports.SmartRollupAddMessagesSchema = exports.SmartRollupOriginateSchema = exports.SetDepositsLimitSchema = exports.DrainDelegateSchema = exports.UpdateConsensusKeySchema = exports.IncreasePaidStorageSchema = exports.TransferTicketSchema = exports.RegisterGlobalConstantSchema = exports.ProposalsSchema = exports.SeedNonceRevelationSchema = exports.AttestationWithDalSchema = exports.AttestationSchema = exports.BallotSchema = exports.OriginationSchema = exports.TransactionSchema = exports.DelegationSchema = exports.RevealSchema = exports.ActivationSchema = exports.ManagerOperationSchema = void 0;
|
|
3
|
+
exports.schemaDecoder = exports.schemaEncoder = exports.operationDecoder = exports.operationEncoder = exports.FailingNoopSchema = exports.DalPublishCommitmentSchema = exports.SmartRollupExecuteOutboxMessageSchema = exports.SmartRollupAddMessagesSchema = exports.SmartRollupOriginateSchema = exports.SetDepositsLimitSchema = exports.DrainDelegateSchema = exports.UpdateCompanionKeySchema = exports.UpdateConsensusKeySchema = exports.IncreasePaidStorageSchema = exports.TransferTicketSchema = exports.RegisterGlobalConstantSchema = exports.ProposalsSchema = exports.SeedNonceRevelationSchema = exports.AttestationWithDalSchema = exports.AttestationSchema = exports.BallotSchema = exports.OriginationSchema = exports.TransactionSchema = exports.DelegationSchema = exports.RevealSchema = exports.ActivationSchema = exports.ManagerOperationSchema = void 0;
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
5
|
const core_1 = require("@taquito/core");
|
|
6
6
|
const errors_1 = require("../errors");
|
|
@@ -19,6 +19,7 @@ exports.RevealSchema = {
|
|
|
19
19
|
gas_limit: constants_1.CODEC.ZARITH,
|
|
20
20
|
storage_limit: constants_1.CODEC.ZARITH,
|
|
21
21
|
public_key: constants_1.CODEC.PUBLIC_KEY,
|
|
22
|
+
proof: constants_1.CODEC.SIGNATURE_PROOF,
|
|
22
23
|
};
|
|
23
24
|
exports.DelegationSchema = {
|
|
24
25
|
source: constants_1.CODEC.PKH,
|
|
@@ -115,6 +116,15 @@ exports.UpdateConsensusKeySchema = {
|
|
|
115
116
|
pk: constants_1.CODEC.PUBLIC_KEY,
|
|
116
117
|
proof: constants_1.CODEC.SIGNATURE_PROOF,
|
|
117
118
|
};
|
|
119
|
+
exports.UpdateCompanionKeySchema = {
|
|
120
|
+
source: constants_1.CODEC.PKH,
|
|
121
|
+
fee: constants_1.CODEC.ZARITH,
|
|
122
|
+
counter: constants_1.CODEC.ZARITH,
|
|
123
|
+
gas_limit: constants_1.CODEC.ZARITH,
|
|
124
|
+
storage_limit: constants_1.CODEC.ZARITH,
|
|
125
|
+
pk: constants_1.CODEC.PUBLIC_KEY,
|
|
126
|
+
proof: constants_1.CODEC.SIGNATURE_PROOF,
|
|
127
|
+
};
|
|
118
128
|
exports.DrainDelegateSchema = {
|
|
119
129
|
consensus_key: constants_1.CODEC.PKH,
|
|
120
130
|
delegate: constants_1.CODEC.PKH,
|