Socket
Socket
Sign inDemoInstall

@aeternity/aepp-calldata

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aeternity/aepp-calldata - npm Package Compare versions

Comparing version 1.7.0 to 1.8.0

src/Serializers/ContractBytecodeSerializer.js

12

package.json
{
"name": "@aeternity/aepp-calldata",
"description": "Aeternity data serialization library",
"version": "1.7.0",
"version": "1.8.0",
"author": "aeternity",

@@ -35,3 +35,3 @@ "license": "ISC",

"blakejs": "^1.2.1",
"bs58": "^5.0.0",
"bs58": "^6.0.0",
"rlp": "^3.0.0",

@@ -42,4 +42,4 @@ "safe-buffer": "^5.2.1",

"devDependencies": {
"@aeternity/aepp-cli": "^5.0.0",
"ava": "6.1.2",
"@aeternity/aepp-cli": "^6.0.0",
"ava": "6.1.3",
"benchmark": "2.1.4",

@@ -50,4 +50,4 @@ "browserify": "17.0.0",

"eslint-plugin-import": "2.29.1",
"nyc": "15.1.0",
"tape": "5.7.5"
"nyc": "17.0.0",
"tape": "5.8.1"
},

@@ -54,0 +54,0 @@ "ava": {

@@ -1,6 +0,6 @@

const RLP = require('rlp')
const ApiEncoder = require('./ApiEncoder')
const Serializer = require('./Serializer')
const BytecodeSerializer = require('./Serializers/BytecodeSerializer')
const {byteArray2Int, byteArray2Hex} = require('./utils/int2ByteArray')
const ContractBytecodeSerializer = require('./Serializers/ContractBytecodeSerializer')
const IntSerializer = require('./Serializers/IntSerializer')
const FateTag = require('./FateTag')

@@ -10,3 +10,4 @@ class ContractEncoder {

this._apiEncoder = new ApiEncoder()
this._bytecodeSerializer = new BytecodeSerializer(new Serializer())
this._contractBytecodeSerializer = new ContractBytecodeSerializer(new Serializer())
this._intSerializer = new IntSerializer()
}

@@ -21,15 +22,11 @@

decode(data) {
const binData = this._apiEncoder.decodeWithType(data, 'contract_bytearray')
const decoded = RLP.decode(binData, true)
const stringDecoder = new TextDecoder()
const bytecode = this._apiEncoder.decodeWithType(data, 'contract_bytearray')
return {
tag: byteArray2Int(decoded.data[0]),
vsn: byteArray2Int(decoded.data[1]),
sourceHash: byteArray2Hex(decoded.data[2]),
aevmTypeInfo: decoded.data[3],
compilerVersion: stringDecoder.decode(decoded.data[5]),
payable: Boolean(decoded.data[6][0]),
bytecode: this._bytecodeSerializer.deserialize(new Uint8Array(decoded.data[4]))
}
const fateContractBytearray = new Uint8Array([
FateTag.CONTRACT_BYTEARRAY,
...this._intSerializer.serialize(bytecode.length),
...bytecode,
])
return this._contractBytecodeSerializer.deserialize(fateContractBytearray)
}

@@ -36,0 +33,0 @@ }

@@ -45,3 +45,3 @@ /* eslint-disable key-spacing, indent */

FALSE : 0b01111111, // 0111 1111
// 1000 1111 - FREE (Possibly for bytecode in the future.)
CONTRACT_BYTEARRAY: 0b10001111, // 1000 1111
OBJECT : 0b10011111, // 1001 1111 | ObjectType | RLP encoded Array

@@ -48,0 +48,0 @@ VARIANT : 0b10101111, // 1010 1111 | [encoded arities] | encoded tag | [encoded values]

@@ -250,2 +250,6 @@ const FateTypeVoid = () => {

const FateTypeContractBytearray = () => {
return {name: 'contract_bytearray'}
}
const FateTypeVar = (id) => {

@@ -297,4 +301,5 @@ return {

FateTypeCalldata,
FateTypeContractBytearray,
FateTypeVar,
FateTypeAny,
}

@@ -23,2 +23,3 @@ const TypeFactory = require('./TypeFactory')

const CalldataSerializer = require('./Serializers/CalldataSerializer')
const ContractBytecodeSerializer = require('./Serializers/ContractBytecodeSerializer')
const TypeSerializer = require('./Serializers/TypeSerializer')

@@ -56,2 +57,3 @@ const SerializerError = require('./Errors/SerializerError')

'calldata': new CalldataSerializer(this),
'contract_bytearray': new ContractBytecodeSerializer(this),
'type': new TypeSerializer(),

@@ -58,0 +60,0 @@ }

@@ -72,3 +72,3 @@ const RLP = require('rlp')

if (prefix !== 0xfe) {
throw new Error(`Wrong function prefix, expeted 0xfe got 0x${data[0].toString(16)}`)
throw new Error(`Wrong function prefix, expected 0xfe got 0x${data[0].toString(16)}`)
}

@@ -75,0 +75,0 @@

@@ -5,2 +5,3 @@ const FateTag = require('../FateTag')

const FatePrefixError = require('../Errors/FatePrefixError')
const FateTypeError = require('../Errors/FateTypeError')
const {

@@ -48,2 +49,60 @@ FateTypeInt,

serialize(type) {
const basicTypeTag = Object.entries(BASIC_TYPES)
.find(([_key, { name }]) => name === type.name)?.[0]
if (basicTypeTag != null) {
return new Uint8Array([basicTypeTag])
}
const objectTypeTag = Object.entries(OBJECT_TYPES)
.find(([_key, { name }]) => name === type.name)?.[0]
if (objectTypeTag != null) {
return new Uint8Array([FateTag.TYPE_OBJECT, objectTypeTag])
}
if (type.name === 'tvar') {
return new Uint8Array([FateTag.TYPE_VAR, type.id])
}
if (type.name === 'bytes') {
return new Uint8Array([
FateTag.TYPE_BYTES,
...this._intSerializer.serialize(type.size),
])
}
if (type.name === 'list') {
return new Uint8Array([
FateTag.TYPE_LIST,
...this.serialize(type.valuesType),
])
}
if (type.name === 'map') {
return new Uint8Array([
FateTag.TYPE_MAP,
...this.serialize(type.keyType),
...this.serialize(type.valueType),
])
}
if (type.name === 'tuple') {
return new Uint8Array([
FateTag.TYPE_TUPLE,
type.valueTypes.length,
...type.valueTypes.map((t) => [...this.serialize(t)]).flat(),
])
}
if (type.name === 'variant') {
return new Uint8Array([
FateTag.TYPE_VARIANT,
type.variants.length,
...type.variants.map((t) => [...this.serialize(t)]).flat(),
])
}
throw new FateTypeError(type.name, `Unsupported type: ${type.name}`)
}
deserializeStream(data) {

@@ -50,0 +109,0 @@ const buffer = new Uint8Array(data)

@@ -19,2 +19,3 @@ const assert = require('./utils/assert')

FateTypeVariant,
FateTypeContractBytearray,
FateTypeType,

@@ -84,2 +85,6 @@ } = require('./FateTypes')

if (tag === FateTag.CONTRACT_BYTEARRAY) {
return FateTypeContractBytearray()
}
if (tag === FateTag.TYPE_INTEGER

@@ -86,0 +91,0 @@ || tag === FateTag.TYPE_BOOLEAN

@@ -1,2 +0,2 @@

const bs58 = require('bs58')
const bs58 = require('bs58').default
const { addChecksum, getPayload } = require('./base64check')

@@ -3,0 +3,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc