Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

as-chain

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

as-chain - npm Package Compare versions

Comparing version 0.0.40 to 0.0.41

assembly/bignum/fixed/fp128.ts

42

assembly/asset.ts

@@ -34,2 +34,44 @@ import { check } from "./system";

export class SymbolCode implements Packer {
public value: u64;
constructor(name: string="") {
check(name.length <= 7, "bad symbol name");
this.value = 0;
for (let i=0; i<name.length; i++) {
let v: u64 = <u64>name.charCodeAt(name.length-1-i);
check(v >= 65 && v <= 90, "Invalid character");
this.value <<= 8;
this.value |= v;
}
}
pack(): u8[] {
let enc = new Encoder(8);
enc.packNumber<u64>(this.value);
return enc.getBytes();
}
unpack(data: u8[]): usize {
let dec = new Decoder(data);
this.value = dec.unpackNumber<u64>();
check(isValid(this.value), "invalid symbol");
return dec.getPos();
}
getSize(): usize {
return 8;
}
@inline @operator('==')
static eq(a: SymbolCode, b: SymbolCode): bool {
return a.value == b.value;
}
@inline @operator('!=')
static neq(a: SymbolCode, b: SymbolCode): bool {
return a.value != b.value;
}
}
export class Symbol implements Packer {

@@ -36,0 +78,0 @@ public value: u64;

95

assembly/bignum.ts

@@ -1,97 +0,4 @@

import { i128, u128, u256 } from "as-bignum";
import { Encoder, Decoder, Packer } from "./serializer";
export { i128 as I128, u128 as U128, u256 as U256} from "./bignum/integer";
export class I128 extends i128 implements Packer {
pack(): u8[] {
let enc = new Encoder(16);
enc.packNumber<u64>(this.lo);
enc.packNumber<i64>(this.hi);
return enc.getBytes();
}
unpack(data: u8[]): usize {
let dec = new Decoder(data);
this.lo = dec.unpackNumber<u64>();
this.hi = dec.unpackNumber<i64>();
return 16;
}
getSize(): usize {
return 16;
}
}
export class U128 extends u128 implements Packer {
pack(): u8[] {
let enc = new Encoder(16);
enc.packNumber<u64>(this.lo);
enc.packNumber<u64>(this.hi);
return enc.getBytes();
}
unpack(data: u8[]): usize {
let dec = new Decoder(data);
this.lo = dec.unpackNumber<u64>();
this.hi = dec.unpackNumber<u64>();
return 16;
}
getSize(): usize {
return 16;
}
@inline @operator('+')
static add(a: U128, b: U128): U128 {
let ret = u128.add(a, b);
return new U128(ret.lo, ret.hi);
}
@inline @operator('-')
static sub(a: U128, b: U128): U128 {
let ret = u128.sub(a, b);
return new U128(ret.lo, ret.hi);
}
// mul: u128 x u128 = u128
@inline @operator('*')
static mul(a: U128, b: U128): U128 {
let ret = u128.mul(a, b);
return new U128(ret.lo, ret.hi);
}
@inline @operator('/')
static div(a: U128, b: U128): U128 {
let ret = u128.div(a, b);
return new U128(ret.lo, ret.hi);
}
@inline @operator('%')
static rem(a: U128, b: U128): U128 {
let ret = u128.rem(a, b);
return new U128(ret.lo, ret.hi);
}
}
export class U256 extends u256 implements Packer {
pack(): u8[] {
let enc = new Encoder(32);
enc.packNumber<u64>(this.lo1);
enc.packNumber<u64>(this.lo2);
enc.packNumber<u64>(this.hi1);
enc.packNumber<u64>(this.hi2);
return enc.getBytes();
}
unpack(data: u8[]): usize {
let dec = new Decoder(data);
this.lo1 = dec.unpackNumber<u64>();
this.lo2 = dec.unpackNumber<u64>();
this.hi1 = dec.unpackNumber<u64>();
this.hi2 = dec.unpackNumber<u64>();
return 32;
}
getSize(): usize {
return 32;
}
}

@@ -8,16 +8,2 @@ import { PermissionLevel, Action } from "./action"

export class ActionWrapperAct {
constructor(
public action: Name,
public contract: Name,
public permissionLevel: PermissionLevel
){}
send <T extends Packer>(data: T): void {
const permissions = [this.permissionLevel]
const action = new Action(permissions, this.contract, this.action, data.pack())
action.send()
}
}
export class Variant implements Packer {

@@ -53,11 +39,27 @@ _index: u8;

export class ActionWrapper {
export class InlineActionAct <T extends Packer> {
constructor(
public action: Name = new Name()
public action: Name,
public contract: Name,
public permissionLevel: PermissionLevel
){}
static fromString(s: string): ActionWrapper {
return new ActionWrapper(Name.fromString(s))
send(data: T): void {
const permissions = [this.permissionLevel]
const action = new Action(permissions, this.contract, this.action, data.pack())
action.send()
}
}
export class InlineAction <T extends Packer> {
public action: Name
constructor(action: string){
this.action = Name.fromString(action)
}
static fromName<T extends Packer>(name: Name): InlineAction<T> {
return new InlineAction<T>(name.toString())
}
/**

@@ -70,7 +72,7 @@ * Create an action with act given contract, actor, and permission

*/
act (
act(
contract: Name,
permissionLevel: PermissionLevel
): ActionWrapperAct {
return new ActionWrapperAct(this.action, contract, permissionLevel)
): InlineActionAct<T> {
return new InlineActionAct(this.action, contract, permissionLevel)
}

@@ -125,2 +127,2 @@ }

export class Table extends MockPacker {}
export class InlineAction extends Table {}
export class ActionData extends MockPacker {}

@@ -13,3 +13,3 @@ export { U128, U256, I128 } from "./bignum";

export { VariantValue } from "./variant";
export { Optional } from "./optional";
export { Optional, OptionalNumber, OptionalString } from "./optional";
export { BinaryExtension } from "./binaryextension";

@@ -65,3 +65,3 @@

export {Contract, ActionWrapper, Table, InlineAction, Variant} from "./helpers"
export {Contract, Table, InlineAction, ActionData, Variant} from "./helpers"

@@ -84,3 +84,3 @@ export {

export { Action, PermissionLevel } from "./action";
export { Asset, ExtendedAsset, Symbol, ExtendedSymbol, isValid } from "./asset";
export { Asset, ExtendedAsset, Symbol, SymbolCode, ExtendedSymbol, isValid } from "./asset";

@@ -87,0 +87,0 @@ export {

import { Packer, Encoder, Decoder } from "./serializer"
import { Utils } from "./utils"

@@ -42,2 +43,89 @@ export class Optional<T extends Packer> implements Packer {

}
}
export class OptionalNumber<T> implements Packer {
value: T;
hasValue: bool;
constructor(
value: T = 0, hasValue: bool = true
) {
if (hasValue) {
this.value = value;
}
this.hasValue = hasValue;
}
pack(): u8[] {
let enc = new Encoder(this.getSize())
if (this.value) {
enc.packNumber<u8>(1);
enc.packNumber<T>(this.value);
return enc.getBytes();
} else {
enc.packNumber<u8>(0);
return enc.getBytes();
}
}
unpack(data: u8[]): usize {
let dec = new Decoder(data);
let hasValue = dec.unpackNumber<u8>();
if (!hasValue) {
this.hasValue = false;
this.value = 0;
return 1;
}
this.value = dec.unpackNumber<T>();
return dec.getPos();
}
getSize(): usize {
if (!this.value) {
return 1;
}
return 1 + sizeof<T>();
}
}
export class OptionalString implements Packer {
value: string = "";
hasValue: bool;
constructor(
value: string="", hasValue: bool=true
) {
this.value = value;
this.hasValue = hasValue;
}
pack(): u8[] {
let enc = new Encoder(this.getSize())
if (this.hasValue) {
enc.packNumber<u8>(1);
enc.packString(this.value);
return enc.getBytes();
} else {
enc.packNumber<u8>(0);
return enc.getBytes();
}
}
unpack(data: u8[]): usize {
let dec = new Decoder(data)
let hasValue = dec.unpackNumber<u8>();
if (!hasValue) {
this.hasValue = false;
this.value = "";
return 1;
}
this.hasValue = true;
this.value = dec.unpackString();
return dec.getPos();
}
getSize(): usize {
if (!this.hasValue) {
return 1;
}
return 1 + Utils.calcPackedStringLength(this.value);
}
}
{
"name": "as-chain",
"version": "0.0.40",
"version": "0.0.41",
"description": "chain module for assemblyscript",

@@ -29,4 +29,3 @@ "main": "js/index.js",

"dependencies": {
"@assemblyscript/loader": "^0.19.22",
"as-bignum": "^0.2.18"
"@assemblyscript/loader": "^0.19.22"
},

@@ -33,0 +32,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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