New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

beaker-ts

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

beaker-ts - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

8

lib/examples/demo_avm7/demoavm7_client.d.ts

@@ -5,3 +5,3 @@ import algosdk from "algosdk";

ts: bigint;
seed: number[];
seed: Uint8Array;
static codec: algosdk.ABIType;

@@ -29,9 +29,9 @@ static fields: string[];

replace(orig: string, start: bigint, replace_with: string): Promise<ABIResult<string>>;
sha3_256(to_hash: string): Promise<ABIResult<number[]>>;
sha3_256(to_hash: string): Promise<ABIResult<Uint8Array>>;
noop(): Promise<ABIResult<void>>;
block(round: bigint): Promise<ABIResult<BlockDetails>>;
ed25519verify_bare(msg: string, sig: number[]): Promise<ABIResult<boolean>>;
ed25519verify_bare(msg: string, sig: Uint8Array): Promise<ABIResult<boolean>>;
b64decode(b64encoded: string): Promise<ABIResult<string>>;
json_ref(json_str: string): Promise<ABIResult<JsonExampleResult>>;
vrf_verify(msg: number[], proof: number[], pub_key: string): Promise<ABIResult<number[]>>;
vrf_verify(msg: Uint8Array, proof: Uint8Array, pub_key: string): Promise<ABIResult<Uint8Array>>;
}
import algosdk from "algosdk";
import { ApplicationClient, ABIResult, Schema } from "../../";
import { ApplicationClient, ABIResult, Schema } from "../..";
export declare class ExpensiveApp extends ApplicationClient {

@@ -10,4 +10,4 @@ desc: string;

methods: algosdk.ABIMethod[];
hash_it(input: string, iters: number, opup_app: any): Promise<ABIResult<any>>;
opup_bootstrap(ptxn: algosdk.TransactionWithSigner | algosdk.Transaction): Promise<ABIResult<number>>;
hash_it(input: string, iters: bigint, opup_app: bigint): Promise<ABIResult<Uint8Array>>;
opup_bootstrap(ptxn: algosdk.TransactionWithSigner | algosdk.Transaction): Promise<ABIResult<bigint>>;
}

@@ -59,3 +59,3 @@ "use strict";

var algosdk_1 = __importDefault(require("algosdk"));
var __1 = require("../../");
var __1 = require("../..");
var ExpensiveApp = /** @class */ (function (_super) {

@@ -62,0 +62,0 @@ __extends(ExpensiveApp, _super);

@@ -62,7 +62,7 @@ "use strict";

_b.sent();
return [4 /*yield*/, appClient.place_order(1, { item: "cubes", quantity: 1 })];
return [4 /*yield*/, appClient.place_order(BigInt(1), { item: "cubes", quantity: BigInt(1) })];
case 4:
result = _b.sent();
console.log(result.txID);
return [4 /*yield*/, appClient.increase_quantity(1)];
return [4 /*yield*/, appClient.increase_quantity(BigInt(1))];
case 5:

@@ -69,0 +69,0 @@ result2 = _b.sent();

@@ -5,3 +5,3 @@ import algosdk from "algosdk";

item: string;
quantity: number;
quantity: bigint;
static codec: algosdk.ABIType;

@@ -19,5 +19,5 @@ static fields: string[];

methods: algosdk.ABIMethod[];
read_item(order_number: number): Promise<ABIResult<Order>>;
place_order(order_number: number, order: Order): Promise<ABIResult<void>>;
increase_quantity(order_number: number): Promise<ABIResult<Order>>;
read_item(order_number: bigint): Promise<ABIResult<Order>>;
place_order(order_number: bigint, order: Order): Promise<ABIResult<void>>;
increase_quantity(order_number: bigint): Promise<ABIResult<Order>>;
}

@@ -50,2 +50,3 @@ "use strict";

var ALGOSDK_PATH = "algosdk";
var REF_TYPES = ["account", "application", "asset"];
var TXN_TYPES = [

@@ -84,12 +85,12 @@ "txn",

function generateClass(appSpec) {
return typescript_1.factory.createClassDeclaration(undefined, [
typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.ExportKeyword),
], typescript_1.factory.createIdentifier(appSpec.contract.name), undefined, [
return typescript_1.factory.createClassDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.ExportKeyword)], typescript_1.factory.createIdentifier(appSpec.contract.name), undefined, [
typescript_1.factory.createHeritageClause(typescript_1.default.SyntaxKind.ExtendsKeyword, [
typescript_1.factory.createExpressionWithTypeArguments(typescript_1.factory.createIdentifier(CLIENT_NAME), undefined),
]),
], __spreadArray(__spreadArray([], generateContractProperties(appSpec), true), appSpec.contract.methods.map(function (meth) { return generateMethodImpl(meth, appSpec); }), true));
], __spreadArray(__spreadArray([], generateContractProperties(appSpec), true), appSpec.contract.methods.map(function (meth) {
return generateMethodImpl(meth, appSpec);
}), true));
}
function tsTypeFromAbiType(argType) {
if (typeof argType === 'string') {
if (typeof argType === "string") {
if (TXN_TYPES.includes(argType))

@@ -100,28 +101,42 @@ return typescript_1.factory.createUnionTypeNode([

]);
}
try {
// Might be a transaction
var abiType = (typeof argType == 'string') ? algosdk_1.default.ABIType.from(argType) : argType;
switch (abiType.constructor) {
case algosdk_1.default.ABIByteType:
return typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.NumberKeyword);
case algosdk_1.default.ABIUintType:
case algosdk_1.default.ABIUfixedType:
if (REF_TYPES.includes(argType)) {
if (["application", "asset"].includes(argType))
return typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.BigIntKeyword);
case algosdk_1.default.ABIAddressType:
case algosdk_1.default.ABIStringType:
return typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword);
case algosdk_1.default.ABIBoolType:
return typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.BooleanKeyword);
case algosdk_1.default.ABIArrayStaticType:
case algosdk_1.default.ABIArrayDynamicType:
return typescript_1.factory.createArrayTypeNode(tsTypeFromAbiType(abiType.childType));
case algosdk_1.default.ABITupleType:
return typescript_1.factory.createTupleTypeNode([
typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.NumberKeyword),
typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword)
]);
return typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword);
}
}
catch (_a) { }
var abiType = typeof argType === "string" ? algosdk_1.default.ABIType.from(argType) : argType;
switch (abiType.constructor) {
case algosdk_1.default.ABIByteType:
return typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.NumberKeyword);
case algosdk_1.default.ABIUintType:
case algosdk_1.default.ABIUfixedType:
return typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.BigIntKeyword);
case algosdk_1.default.ABIAddressType:
case algosdk_1.default.ABIStringType:
return typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword);
case algosdk_1.default.ABIBoolType:
return typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.BooleanKeyword);
case algosdk_1.default.ABIArrayStaticType:
var asStaticArr = abiType;
switch (asStaticArr.childType.constructor) {
// If its bytes, make it a uint8array
case algosdk_1.default.ABIByteType:
return typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier("Uint8Array"));
}
return typescript_1.factory.createArrayTypeNode(tsTypeFromAbiType(asStaticArr.childType));
case algosdk_1.default.ABIArrayDynamicType:
var asArr = abiType;
switch (asArr.childType.constructor) {
// If its bytes, make it a uint8array
case algosdk_1.default.ABIByteType:
return typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier("Uint8Array"));
}
return typescript_1.factory.createArrayTypeNode(tsTypeFromAbiType(asArr.childType));
case algosdk_1.default.ABITupleType:
var asTuple = abiType;
return typescript_1.factory.createTupleTypeNode(asTuple.childTypes.map(function (elem) {
return tsTypeFromAbiType(elem);
}));
}
return typescript_1.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.AnyKeyword);

@@ -161,8 +176,8 @@ }

abiRetType = tsTypeFromAbiType(method.returns.type.toString());
// Always `output` here because pyteal,
// Always `output` here because pyteal,
// when others app specs come in we should consider them
if (hint.structs !== undefined && 'output' in hint.structs) {
abiRetType = typescript_1.factory.createTypeReferenceNode(hint.structs['output'].name);
resultArgs.push(typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier(hint.structs['output'].name), typescript_1.factory.createIdentifier('decodeResult')), undefined, [
typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier("result"), typescript_1.factory.createIdentifier("returnValue"))
if (hint.structs !== undefined && "output" in hint.structs) {
abiRetType = typescript_1.factory.createTypeReferenceNode(hint.structs["output"].name);
resultArgs.push(typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier(hint.structs["output"].name), typescript_1.factory.createIdentifier("decodeResult")), undefined, [
typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier("result"), typescript_1.factory.createIdentifier("returnValue")),
]));

@@ -173,7 +188,13 @@ }

typescript_1.factory.createVariableStatement(undefined, typescript_1.factory.createVariableDeclarationList([
typescript_1.factory.createVariableDeclaration(typescript_1.factory.createIdentifier("result"), undefined, undefined, typescript_1.factory.createAwaitExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createThis(), typescript_1.factory.createIdentifier("call")), undefined, __spreadArray(__spreadArray([], callArgs, true), [typescript_1.factory.createObjectLiteralExpression(abiMethodArgs)], false))))
typescript_1.factory.createVariableDeclaration(typescript_1.factory.createIdentifier("result"), undefined, undefined, typescript_1.factory.createAwaitExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createThis(), typescript_1.factory.createIdentifier("call")), undefined, __spreadArray(__spreadArray([], callArgs, true), [
typescript_1.factory.createObjectLiteralExpression(abiMethodArgs),
], false)))),
], typescript_1.default.NodeFlags.Const)),
typescript_1.factory.createReturnStatement(typescript_1.factory.createNewExpression(typescript_1.factory.createIdentifier("ABIResult"), [abiRetType], resultArgs))
typescript_1.factory.createReturnStatement(typescript_1.factory.createNewExpression(typescript_1.factory.createIdentifier("ABIResult"), [abiRetType], resultArgs)),
], true);
var retType = typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier("Promise"), [typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier("ABIResult"), [abiRetType])]);
var retType = typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier("Promise"), [
typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier("ABIResult"), [
abiRetType,
]),
]);
var methodSpec = typescript_1.factory.createMethodDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.AsyncKeyword)], undefined, method.name, undefined, undefined, params, retType, body);

@@ -232,13 +253,23 @@ return methodSpec;

members.push(typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], typescript_1.factory.createIdentifier("codec"), undefined, typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createQualifiedName(typescript_1.factory.createIdentifier("algosdk"), typescript_1.factory.createIdentifier("ABIType")), undefined), typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier("algosdk"), typescript_1.factory.createIdentifier("ABIType")), typescript_1.factory.createIdentifier("from")), undefined, [typescript_1.factory.createStringLiteral("(".concat(tupleTypes.join(","), ")"))])));
members.push(typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], typescript_1.factory.createIdentifier("fields"), undefined, typescript_1.factory.createTypeReferenceNode("string[]"), typescript_1.factory.createArrayLiteralExpression(tupleNames.map(function (name) { return typescript_1.factory.createStringLiteral(name); }))));
members.push(typescript_1.factory.createPropertyDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], typescript_1.factory.createIdentifier("fields"), undefined, typescript_1.factory.createTypeReferenceNode("string[]"), typescript_1.factory.createArrayLiteralExpression(tupleNames.map(function (name) {
return typescript_1.factory.createStringLiteral(name);
}))));
members.push(
// Add static `decodeResult(val: ABIValue): <T>` method
typescript_1.factory.createMethodDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], undefined, typescript_1.factory.createIdentifier("decodeResult"), undefined, undefined, [typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, typescript_1.factory.createIdentifier("val"), undefined, typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createQualifiedName(typescript_1.factory.createIdentifier("algosdk"), typescript_1.factory.createIdentifier("ABIValue")), undefined), undefined)], typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier(s.name), undefined), typescript_1.factory.createBlock([typescript_1.factory.createReturnStatement(typescript_1.factory.createAsExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier("decodeNamedTuple"), undefined, [
typescript_1.factory.createMethodDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], undefined, typescript_1.factory.createIdentifier("decodeResult"), undefined, undefined, [
typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, typescript_1.factory.createIdentifier("val"), undefined, typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createQualifiedName(typescript_1.factory.createIdentifier("algosdk"), typescript_1.factory.createIdentifier("ABIValue")), undefined), undefined),
], typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier(s.name), undefined), typescript_1.factory.createBlock([
typescript_1.factory.createReturnStatement(typescript_1.factory.createAsExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier("decodeNamedTuple"), undefined, [
typescript_1.factory.createIdentifier("val"),
typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier(s.name), typescript_1.factory.createIdentifier("fields")),
]), typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier(s.name), undefined)))], true)));
members.push(typescript_1.factory.createMethodDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], undefined, typescript_1.factory.createIdentifier("decodeBytes"), undefined, undefined, [typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, typescript_1.factory.createIdentifier("val"), undefined, typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier("Uint8Array"), undefined), undefined)], typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier(s.name), undefined), typescript_1.factory.createBlock([typescript_1.factory.createReturnStatement(typescript_1.factory.createAsExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier("decodeNamedTuple"), undefined, [
]), typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier(s.name), undefined))),
], true)));
members.push(typescript_1.factory.createMethodDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.StaticKeyword)], undefined, typescript_1.factory.createIdentifier("decodeBytes"), undefined, undefined, [
typescript_1.factory.createParameterDeclaration(undefined, undefined, undefined, typescript_1.factory.createIdentifier("val"), undefined, typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier("Uint8Array"), undefined), undefined),
], typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier(s.name), undefined), typescript_1.factory.createBlock([
typescript_1.factory.createReturnStatement(typescript_1.factory.createAsExpression(typescript_1.factory.createCallExpression(typescript_1.factory.createIdentifier("decodeNamedTuple"), undefined, [
typescript_1.factory.createCallExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier(s.name), typescript_1.factory.createIdentifier("codec")), typescript_1.factory.createIdentifier("decode")), undefined, [typescript_1.factory.createIdentifier("val")]),
typescript_1.factory.createPropertyAccessExpression(typescript_1.factory.createIdentifier(s.name), typescript_1.factory.createIdentifier("fields")),
]), typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier(s.name), undefined)))], true)));
]), typescript_1.factory.createTypeReferenceNode(typescript_1.factory.createIdentifier(s.name), undefined))),
], true)));
return typescript_1.factory.createClassDeclaration(undefined, [typescript_1.factory.createModifier(typescript_1.default.SyntaxKind.ExportKeyword)], typescript_1.factory.createIdentifier(s.name), undefined, undefined, members);

@@ -245,0 +276,0 @@ }

{
"name": "beaker-ts",
"version": "0.0.9",
"version": "0.0.10",
"description": "",

@@ -11,2 +11,3 @@ "main": "./lib/index.js",

"avm7": "npx ts-node src/examples/demo_avm7/demo_avm7_example.ts",

@@ -13,0 +14,0 @@ "build": "tsc -p .",

@@ -44,4 +44,4 @@ # Beaker Typescript Client Generator

See the [examples directory](https://github.com/algorand-devrel/beaker-ts/src/examples/) for usage examples.
See the [examples directory](https://github.com/algorand-devrel/beaker-ts/tree/master/src/examples) for usage examples.
Please report issues (bound to be lots)
import algosdk from "algosdk";
import {ApplicationClient, ABIResult, decodeNamedTuple, Schema, AVMType} from "../../";
import {ApplicationClient, ABIResult, decodeNamedTuple, Schema, AVMType} from "../..";
export class ExpensiveApp extends ApplicationClient {

@@ -13,10 +13,10 @@ desc: string = "";

];
async hash_it(input: string, iters: number, opup_app: any): Promise<ABIResult<any>> {
async hash_it(input: string, iters: bigint, opup_app: bigint): Promise<ABIResult<Uint8Array>> {
const result = await this.call(algosdk.getMethodByName(this.methods, "hash_it"), { input: input, iters: iters, opup_app: opup_app });
return new ABIResult<any>(result);
return new ABIResult<Uint8Array>(result);
}
async opup_bootstrap(ptxn: algosdk.TransactionWithSigner | algosdk.Transaction): Promise<ABIResult<number>> {
async opup_bootstrap(ptxn: algosdk.TransactionWithSigner | algosdk.Transaction): Promise<ABIResult<bigint>> {
const result = await this.call(algosdk.getMethodByName(this.methods, "opup_bootstrap"), { ptxn: ptxn });
return new ABIResult<number>(result);
return new ABIResult<bigint>(result);
}
}

@@ -19,6 +19,6 @@ import { isUint8Array } from 'util/types';

const result = await appClient.place_order(1, {item: "cubes", quantity: 1});
const result = await appClient.place_order(BigInt(1), {item: "cubes", quantity: BigInt(1)});
console.log(result.txID);
const result2 = await appClient.increase_quantity(1);
const result2 = await appClient.increase_quantity(BigInt(1));
console.log("Result: ", result2.value);

@@ -25,0 +25,0 @@ console.log("Or: ", Order.decodeResult(result2.returnValue));

@@ -5,3 +5,3 @@ import algosdk from "algosdk";

item: string;
quantity: number;
quantity: bigint;
static codec: algosdk.ABIType = algosdk.ABIType.from("(string,uint16)");

@@ -27,11 +27,11 @@ static fields: string[] = ["item", "quantity"];

];
async read_item(order_number: number): Promise<ABIResult<Order>> {
async read_item(order_number: bigint): Promise<ABIResult<Order>> {
const result = await this.call(algosdk.getMethodByName(this.methods, "read_item"), { order_number: order_number });
return new ABIResult<Order>(result, Order.decodeResult(result.returnValue));
}
async place_order(order_number: number, order: Order): Promise<ABIResult<void>> {
async place_order(order_number: bigint, order: Order): Promise<ABIResult<void>> {
const result = await this.call(algosdk.getMethodByName(this.methods, "place_order"), { order_number: order_number, order: order });
return new ABIResult<void>(result);
}
async increase_quantity(order_number: number): Promise<ABIResult<Order>> {
async increase_quantity(order_number: bigint): Promise<ABIResult<Order>> {
const result = await this.call(algosdk.getMethodByName(this.methods, "increase_quantity"), { order_number: order_number });

@@ -38,0 +38,0 @@ return new ABIResult<Order>(result, Order.decodeResult(result.returnValue));

@@ -28,2 +28,4 @@ import {

const REF_TYPES: string[] = ["account", "application", "asset"];
const TXN_TYPES: string[] = [

@@ -129,7 +131,13 @@ "txn",

]);
if (REF_TYPES.includes(argType)) {
if (["application", "asset"].includes(argType))
return factory.createKeywordTypeNode(ts.SyntaxKind.BigIntKeyword);
return factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);
}
}
// Might be a transaction
const abiType =
typeof argType == "string" ? algosdk.ABIType.from(argType) : argType;
typeof argType === "string" ? algosdk.ABIType.from(argType) : argType;
switch (abiType.constructor) {

@@ -136,0 +144,0 @@ case algosdk.ABIByteType:

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