@algorandfoundation/algorand-typescript 0.0.1-alpha.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/arc4/encoded-types.d.ts +65 -0
- package/arc4/index.d.ts +57 -0
- package/base-contract.d.ts +5 -0
- package/box.d.ts +52 -0
- package/execution-context.d.ts +40 -0
- package/gtxn.d.ts +30 -0
- package/impl/base-32.d.ts +2 -0
- package/impl/encoding-util.d.ts +8 -0
- package/impl/errors.d.ts +28 -0
- package/impl/name-of-type.d.ts +1 -0
- package/impl/primitives.d.ts +77 -0
- package/impl/state.d.ts +24 -0
- package/index-7MfWJL4Q.js +741 -0
- package/index-7MfWJL4Q.js.map +1 -0
- package/index.d.ts +14 -0
- package/index.mjs +364 -0
- package/index.mjs.map +1 -0
- package/index2.mjs +3 -0
- package/index2.mjs.map +1 -0
- package/internal.d.ts +6 -0
- package/itxn.d.ts +161 -0
- package/op-types.d.ts +2102 -0
- package/op.d.ts +55 -0
- package/package.json +32 -0
- package/primitives.d.ts +55 -0
- package/reference.d.ts +207 -0
- package/state.d.ts +28 -0
- package/transactions.d.ts +342 -0
- package/typescript-helpers.d.ts +2 -0
- package/util.d.ts +31 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
import { biguint, BigUintCompat, bytes, BytesBacked, StringCompat, uint64, Uint64Compat } from '../primitives';
|
2
|
+
import { Account } from '../reference';
|
3
|
+
export type BitSize = 8 | 16 | 32 | 64 | 128 | 256 | 512;
|
4
|
+
type NativeForArc4Int<N extends BitSize> = N extends 8 | 16 | 32 | 64 ? uint64 : biguint;
|
5
|
+
type CompatForArc4Int<N extends BitSize> = N extends 8 | 16 | 32 | 64 ? Uint64Compat : BigUintCompat;
|
6
|
+
declare abstract class AbiEncoded implements BytesBacked {
|
7
|
+
get bytes(): bytes;
|
8
|
+
}
|
9
|
+
export declare class Str extends AbiEncoded {
|
10
|
+
constructor(s: StringCompat);
|
11
|
+
get native(): string;
|
12
|
+
}
|
13
|
+
export declare class UintN<N extends BitSize> extends AbiEncoded {
|
14
|
+
constructor(v?: CompatForArc4Int<N>);
|
15
|
+
get native(): NativeForArc4Int<N>;
|
16
|
+
}
|
17
|
+
export declare class UFixedNxM<N extends BitSize, M extends number> {
|
18
|
+
constructor(v: `${number}:${number}`, n?: N, m?: M);
|
19
|
+
get native(): NativeForArc4Int<N>;
|
20
|
+
}
|
21
|
+
export declare class Byte extends UintN<8> {
|
22
|
+
constructor(v: Uint64Compat);
|
23
|
+
get native(): uint64;
|
24
|
+
}
|
25
|
+
export declare class Bool {
|
26
|
+
#private;
|
27
|
+
constructor(v: boolean);
|
28
|
+
get native(): boolean;
|
29
|
+
}
|
30
|
+
declare abstract class Arc4Array<TItem> extends AbiEncoded {
|
31
|
+
protected items: TItem[];
|
32
|
+
protected constructor(items: TItem[]);
|
33
|
+
get length(): uint64;
|
34
|
+
at(index: Uint64Compat): TItem;
|
35
|
+
slice(start: Uint64Compat, end: Uint64Compat): DynamicArray<TItem>;
|
36
|
+
[Symbol.iterator](): IterableIterator<TItem>;
|
37
|
+
entries(): IterableIterator<readonly [uint64, TItem]>;
|
38
|
+
keys(): IterableIterator<uint64>;
|
39
|
+
}
|
40
|
+
export declare class StaticArray<TItem, TLength extends number> extends Arc4Array<TItem> {
|
41
|
+
constructor();
|
42
|
+
constructor(...items: TItem[] & {
|
43
|
+
length: TLength;
|
44
|
+
});
|
45
|
+
constructor(...items: TItem[]);
|
46
|
+
copy(): StaticArray<TItem, TLength>;
|
47
|
+
}
|
48
|
+
export declare class DynamicArray<TItem> extends Arc4Array<TItem> {
|
49
|
+
constructor(...items: TItem[]);
|
50
|
+
push(...items: TItem[]): void;
|
51
|
+
pop(): TItem;
|
52
|
+
copy(): DynamicArray<TItem>;
|
53
|
+
}
|
54
|
+
type ItemAt<TTuple extends unknown[], TIndex extends number> = undefined extends TTuple[TIndex] ? never : TTuple[TIndex];
|
55
|
+
export declare class Tuple<TTuple extends unknown[]> {
|
56
|
+
#private;
|
57
|
+
constructor(...items: TTuple);
|
58
|
+
at<TIndex extends number>(index: TIndex): ItemAt<TTuple, TIndex>;
|
59
|
+
get native(): TTuple;
|
60
|
+
}
|
61
|
+
export declare class Address extends StaticArray<Byte, 32> {
|
62
|
+
constructor(value: Account | string | bytes);
|
63
|
+
get native(): Account;
|
64
|
+
}
|
65
|
+
export {};
|
package/arc4/index.d.ts
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
import { BaseContract } from '../base-contract';
|
2
|
+
import { DeliberateAny } from '../typescript-helpers';
|
3
|
+
export * from './encoded-types';
|
4
|
+
export declare class Contract extends BaseContract {
|
5
|
+
approvalProgram(): boolean;
|
6
|
+
}
|
7
|
+
export type CreateOptions = 'allow' | 'disallow' | 'require';
|
8
|
+
export type OnCompleteActionStr = 'NoOp' | 'OptIn' | 'ClearState' | 'CloseOut' | 'UpdateApplication' | 'DeleteApplication';
|
9
|
+
export declare enum OnCompleteAction {
|
10
|
+
NoOp,
|
11
|
+
OptIn,
|
12
|
+
CloseOut,
|
13
|
+
ClearState,
|
14
|
+
UpdateApplication,
|
15
|
+
DeleteApplication
|
16
|
+
}
|
17
|
+
export type DefaultArgument<TContract extends Contract> = {
|
18
|
+
constant: string | boolean | number | bigint;
|
19
|
+
} | {
|
20
|
+
from: keyof TContract;
|
21
|
+
};
|
22
|
+
export type AbiMethodConfig<TContract extends Contract> = {
|
23
|
+
/**
|
24
|
+
* Which on complete action(s) are allowed when invoking this method.
|
25
|
+
* @default 'NoOp'
|
26
|
+
*/
|
27
|
+
allowActions?: OnCompleteActionStr | OnCompleteActionStr[];
|
28
|
+
/**
|
29
|
+
* Whether this method should be callable when creating the application.
|
30
|
+
* @default 'disallow'
|
31
|
+
*/
|
32
|
+
onCreate?: CreateOptions;
|
33
|
+
/**
|
34
|
+
* Does the method only perform read operations (no mutation of chain state)
|
35
|
+
* @default false
|
36
|
+
*/
|
37
|
+
readonly?: boolean;
|
38
|
+
/**
|
39
|
+
* Override the name used to generate the abi method selector
|
40
|
+
*/
|
41
|
+
name?: string;
|
42
|
+
defaultArguments?: Record<string, DefaultArgument<TContract>>;
|
43
|
+
};
|
44
|
+
export declare function abimethod<TContract extends Contract>(config?: AbiMethodConfig<TContract>): <TArgs extends DeliberateAny[], TReturn>(target: (this: TContract, ...args: TArgs) => TReturn, ctx: ClassMethodDecoratorContext<TContract>) => (this: TContract, ...args: TArgs) => TReturn;
|
45
|
+
export type BareMethodConfig = {
|
46
|
+
/**
|
47
|
+
* Which on complete action(s) are allowed when invoking this method.
|
48
|
+
* @default 'NoOp'
|
49
|
+
*/
|
50
|
+
allowActions?: OnCompleteActionStr | OnCompleteActionStr[];
|
51
|
+
/**
|
52
|
+
* Whether this method should be callable when creating the application.
|
53
|
+
* @default 'disallow'
|
54
|
+
*/
|
55
|
+
onCreate?: CreateOptions;
|
56
|
+
};
|
57
|
+
export declare function baremethod<TContract extends Contract>(config?: BareMethodConfig): <TArgs extends DeliberateAny[], TReturn>(target: (this: TContract, ...args: TArgs) => TReturn, ctx: ClassMethodDecoratorContext<TContract>) => (this: TContract, ...args: TArgs) => TReturn;
|
package/box.d.ts
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
import { bytes, uint64 } from './primitives';
|
2
|
+
export type Box<TValue> = {
|
3
|
+
readonly key: bytes;
|
4
|
+
value: TValue;
|
5
|
+
readonly exists: boolean;
|
6
|
+
get(options: {
|
7
|
+
default: TValue;
|
8
|
+
}): TValue;
|
9
|
+
delete(): boolean;
|
10
|
+
maybe(): readonly [TValue, boolean];
|
11
|
+
readonly length: uint64;
|
12
|
+
};
|
13
|
+
export type BoxMap<TKey, TValue> = {
|
14
|
+
readonly keyPrefix: bytes;
|
15
|
+
get(key: TKey): TValue;
|
16
|
+
get(key: TKey, options: {
|
17
|
+
default: TValue;
|
18
|
+
}): TValue;
|
19
|
+
set(key: TKey, value: TValue): void;
|
20
|
+
delete(key: TKey): boolean;
|
21
|
+
has(key: TKey): boolean;
|
22
|
+
maybe(key: TKey): readonly [TValue, boolean];
|
23
|
+
length(key: TKey): uint64;
|
24
|
+
};
|
25
|
+
export type BoxRef = {
|
26
|
+
readonly key: bytes;
|
27
|
+
readonly exists: boolean;
|
28
|
+
value: bytes;
|
29
|
+
get(options: {
|
30
|
+
default: bytes;
|
31
|
+
}): bytes;
|
32
|
+
put(value: bytes): bytes;
|
33
|
+
splice(start: uint64, end: uint64, value: bytes): void;
|
34
|
+
replace(start: uint64, value: bytes): void;
|
35
|
+
extract(start: uint64, length: uint64): bytes;
|
36
|
+
delete(): boolean;
|
37
|
+
create(options: {
|
38
|
+
size: uint64;
|
39
|
+
}): boolean;
|
40
|
+
resize(newSize: uint64): void;
|
41
|
+
maybe(): readonly [bytes, boolean];
|
42
|
+
readonly length: uint64;
|
43
|
+
};
|
44
|
+
export declare function Box<TValue>(options: {
|
45
|
+
key: bytes | string;
|
46
|
+
}): Box<TValue>;
|
47
|
+
export declare function BoxMap<TKey, TValue>(options: {
|
48
|
+
keyPrefix: bytes | string;
|
49
|
+
}): BoxMap<TKey, TValue>;
|
50
|
+
export declare function BoxRef(options: {
|
51
|
+
key: bytes | string;
|
52
|
+
}): BoxRef;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { Contract, gtxn, itxn } from '.';
|
2
|
+
import { AbiMethodConfig, BareMethodConfig } from './arc4';
|
3
|
+
import { OpsNamespace } from './op-types';
|
4
|
+
import { bytes, uint64 } from './primitives';
|
5
|
+
import { Account, Application, Asset } from './reference';
|
6
|
+
export type ExecutionContext = {
|
7
|
+
log(value: bytes): void;
|
8
|
+
application(id?: uint64): Application;
|
9
|
+
asset(id?: uint64): Asset;
|
10
|
+
account(address?: bytes): Account;
|
11
|
+
op: Partial<OpsNamespace>;
|
12
|
+
abiMetadata: {
|
13
|
+
captureMethodConfig<T extends Contract>(contract: T, methodName: string, config?: AbiMethodConfig<T> | BareMethodConfig): void;
|
14
|
+
};
|
15
|
+
gtxn: {
|
16
|
+
Transaction: typeof gtxn.Transaction;
|
17
|
+
PaymentTxn: typeof gtxn.PaymentTxn;
|
18
|
+
KeyRegistrationTxn: typeof gtxn.KeyRegistrationTxn;
|
19
|
+
AssetConfigTxn: typeof gtxn.AssetConfigTxn;
|
20
|
+
AssetTransferTxn: typeof gtxn.AssetTransferTxn;
|
21
|
+
AssetFreezeTxn: typeof gtxn.AssetFreezeTxn;
|
22
|
+
ApplicationTxn: typeof gtxn.ApplicationTxn;
|
23
|
+
};
|
24
|
+
itxn: {
|
25
|
+
submitGroup: typeof itxn.submitGroup;
|
26
|
+
payment: typeof itxn.payment;
|
27
|
+
keyRegistration: typeof itxn.keyRegistration;
|
28
|
+
assetConfig: typeof itxn.assetConfig;
|
29
|
+
assetTransfer: typeof itxn.assetTransfer;
|
30
|
+
assetFreeze: typeof itxn.assetFreeze;
|
31
|
+
applicationCall: typeof itxn.applicationCall;
|
32
|
+
};
|
33
|
+
};
|
34
|
+
declare global {
|
35
|
+
var puyaTsExecutionContext: ExecutionContext | undefined;
|
36
|
+
}
|
37
|
+
export declare const ctxMgr: {
|
38
|
+
instance: ExecutionContext;
|
39
|
+
reset(): void;
|
40
|
+
};
|
package/gtxn.d.ts
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
import { uint64 } from './primitives';
|
2
|
+
import type * as txnTypes from './transactions';
|
3
|
+
declare const isGtxn: unique symbol;
|
4
|
+
export interface PaymentTxn extends txnTypes.PaymentTxn {
|
5
|
+
[isGtxn]?: true;
|
6
|
+
}
|
7
|
+
export interface KeyRegistrationTxn extends txnTypes.KeyRegistrationTxn {
|
8
|
+
[isGtxn]?: true;
|
9
|
+
}
|
10
|
+
export interface AssetConfigTxn extends txnTypes.AssetConfigTxn {
|
11
|
+
[isGtxn]?: true;
|
12
|
+
}
|
13
|
+
export interface AssetTransferTxn extends txnTypes.AssetTransferTxn {
|
14
|
+
[isGtxn]?: true;
|
15
|
+
}
|
16
|
+
export interface AssetFreezeTxn extends txnTypes.AssetFreezeTxn {
|
17
|
+
[isGtxn]?: true;
|
18
|
+
}
|
19
|
+
export interface ApplicationTxn extends txnTypes.ApplicationTxn {
|
20
|
+
[isGtxn]?: true;
|
21
|
+
}
|
22
|
+
export type Transaction = PaymentTxn | KeyRegistrationTxn | AssetConfigTxn | AssetTransferTxn | AssetFreezeTxn | ApplicationTxn;
|
23
|
+
export declare function Transaction(groupIndex: uint64): Transaction;
|
24
|
+
export declare function PaymentTxn(groupIndex: uint64): PaymentTxn;
|
25
|
+
export declare function KeyRegistrationTxn(groupIndex: uint64): KeyRegistrationTxn;
|
26
|
+
export declare function AssetConfigTxn(groupIndex: uint64): AssetConfigTxn;
|
27
|
+
export declare function AssetTransferTxn(groupIndex: uint64): AssetTransferTxn;
|
28
|
+
export declare function AssetFreezeTxn(groupIndex: uint64): AssetFreezeTxn;
|
29
|
+
export declare function ApplicationTxn(groupIndex: uint64): ApplicationTxn;
|
30
|
+
export {};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export declare const uint8ArrayToBigInt: (v: Uint8Array) => bigint;
|
2
|
+
export declare const bigIntToUint8Array: (val: bigint, fixedSize?: number | "dynamic") => Uint8Array;
|
3
|
+
export declare const utf8ToUint8Array: (value: string) => Uint8Array;
|
4
|
+
export declare const uint8ArrayToUtf8: (value: Uint8Array) => string;
|
5
|
+
export declare const uint8ArrayToHex: (value: Uint8Array) => string;
|
6
|
+
export declare const uint8ArrayToBase64: (value: Uint8Array) => string;
|
7
|
+
export declare const uint8ArrayToBase64Url: (value: Uint8Array) => string;
|
8
|
+
export { uint8ArrayToBase32 } from './base-32';
|
package/impl/errors.d.ts
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
/**
|
2
|
+
* Raised when an `err` op is encountered, or when the testing VM is asked to do something that would cause
|
3
|
+
* the AVM to fail.
|
4
|
+
*/
|
5
|
+
export declare class AvmError extends Error {
|
6
|
+
constructor(message: string);
|
7
|
+
}
|
8
|
+
export declare function avmError(message: string): never;
|
9
|
+
/**
|
10
|
+
* Raised when an assertion fails
|
11
|
+
*/
|
12
|
+
export declare class AssertError extends AvmError {
|
13
|
+
constructor(message: string);
|
14
|
+
}
|
15
|
+
/**
|
16
|
+
* Raised when testing code errors
|
17
|
+
*/
|
18
|
+
export declare class InternalError extends Error {
|
19
|
+
constructor(message: string, options?: ErrorOptions);
|
20
|
+
}
|
21
|
+
export declare function internalError(message: string): never;
|
22
|
+
/**
|
23
|
+
* Raised when unsupported user code is encountered
|
24
|
+
*/
|
25
|
+
export declare class CodeError extends Error {
|
26
|
+
constructor(message: string, options?: ErrorOptions);
|
27
|
+
}
|
28
|
+
export declare function codeError(message: string): never;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const nameOfType: (x: unknown) => string;
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import type { biguint, BigUintCompat, bytes, BytesCompat, uint64, Uint64Compat } from '../index';
|
2
|
+
export type StubBigUintCompat = BigUintCompat | BigUintCls | Uint64Cls;
|
3
|
+
export type StubBytesCompat = BytesCompat | BytesCls;
|
4
|
+
export type StubUint64Compat = Uint64Compat | Uint64Cls;
|
5
|
+
export declare function toExternalValue(val: uint64): bigint;
|
6
|
+
export declare function toExternalValue(val: biguint): bigint;
|
7
|
+
export declare function toExternalValue(val: bytes): Uint8Array;
|
8
|
+
export declare function toExternalValue(val: string): string;
|
9
|
+
export declare const toBytes: (val: unknown) => bytes;
|
10
|
+
export declare const isBytes: (v: unknown) => v is StubBytesCompat;
|
11
|
+
export declare const isUint64: (v: unknown) => v is StubUint64Compat;
|
12
|
+
export declare const isBigUint: (v: unknown) => v is biguint;
|
13
|
+
export declare const checkUint64: (v: bigint) => bigint;
|
14
|
+
export declare const checkBigUint: (v: bigint) => bigint;
|
15
|
+
export declare const checkBytes: (v: Uint8Array) => Uint8Array;
|
16
|
+
export declare abstract class AlgoTsPrimitiveCls {
|
17
|
+
private readonly _type;
|
18
|
+
constructor(t: string);
|
19
|
+
static [Symbol.hasInstance](x: unknown): x is AlgoTsPrimitiveCls;
|
20
|
+
abstract valueOf(): bigint | string | boolean;
|
21
|
+
abstract toBytes(): BytesCls;
|
22
|
+
}
|
23
|
+
export declare class Uint64Cls extends AlgoTsPrimitiveCls {
|
24
|
+
readonly value: bigint;
|
25
|
+
constructor(value: bigint | number | string);
|
26
|
+
static [Symbol.hasInstance](x: unknown): x is Uint64Cls;
|
27
|
+
static fromCompat(v: StubUint64Compat): Uint64Cls;
|
28
|
+
static getNumber(v: StubUint64Compat): number;
|
29
|
+
valueOf(): bigint;
|
30
|
+
toBytes(isDynamic?: boolean): BytesCls;
|
31
|
+
asAlgoTs(): uint64;
|
32
|
+
asBigInt(): bigint;
|
33
|
+
asNumber(): number;
|
34
|
+
}
|
35
|
+
export declare class BigUintCls extends AlgoTsPrimitiveCls {
|
36
|
+
readonly value: bigint;
|
37
|
+
constructor(value: bigint);
|
38
|
+
valueOf(): bigint;
|
39
|
+
toBytes(): BytesCls;
|
40
|
+
asAlgoTs(): biguint;
|
41
|
+
asBigInt(): bigint;
|
42
|
+
asNumber(): number;
|
43
|
+
static [Symbol.hasInstance](x: unknown): x is BigUintCls;
|
44
|
+
static fromCompat(v: StubBigUintCompat): BigUintCls;
|
45
|
+
}
|
46
|
+
export declare class BytesCls extends AlgoTsPrimitiveCls {
|
47
|
+
#private;
|
48
|
+
constructor(v: Uint8Array);
|
49
|
+
get length(): Uint64Cls;
|
50
|
+
toBytes(): BytesCls;
|
51
|
+
at(i: StubUint64Compat): BytesCls;
|
52
|
+
slice(start: StubUint64Compat, end: StubUint64Compat): BytesCls;
|
53
|
+
concat(other: StubBytesCompat): BytesCls;
|
54
|
+
bitwiseAnd(other: StubBytesCompat): BytesCls;
|
55
|
+
bitwiseOr(other: StubBytesCompat): BytesCls;
|
56
|
+
bitwiseXor(other: StubBytesCompat): BytesCls;
|
57
|
+
bitwiseInvert(): BytesCls;
|
58
|
+
equals(other: StubBytesCompat): boolean;
|
59
|
+
private bitwiseOp;
|
60
|
+
valueOf(): string;
|
61
|
+
static [Symbol.hasInstance](x: unknown): x is BytesCls;
|
62
|
+
static fromCompat(v: StubBytesCompat | undefined): BytesCls;
|
63
|
+
static fromInterpolation(template: TemplateStringsArray, replacements: StubBytesCompat[]): BytesCls;
|
64
|
+
static fromHex(hex: string): BytesCls;
|
65
|
+
static fromBase64(b64: string): BytesCls;
|
66
|
+
static fromBase32(b32: string): BytesCls;
|
67
|
+
toUint64(): Uint64Cls;
|
68
|
+
toBigUint(): BigUintCls;
|
69
|
+
toString(): string;
|
70
|
+
asAlgoTs(): bytes;
|
71
|
+
asUint8Array(): Uint8Array;
|
72
|
+
}
|
73
|
+
export declare const arrayUtil: {
|
74
|
+
arrayAt<T>(arrayLike: T[], index: StubUint64Compat): T;
|
75
|
+
arraySlice(arrayLike: Uint8Array, start: StubUint64Compat, end: StubUint64Compat): Uint8Array;
|
76
|
+
arraySlice<T>(arrayLike: T[], start: StubUint64Compat, end: StubUint64Compat): T[];
|
77
|
+
};
|
package/impl/state.d.ts
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
import { bytes } from '../primitives';
|
2
|
+
import { Account } from '../reference';
|
3
|
+
export declare class GlobalStateCls<ValueType> {
|
4
|
+
#private;
|
5
|
+
private readonly _type;
|
6
|
+
key: bytes | undefined;
|
7
|
+
delete: () => void;
|
8
|
+
static [Symbol.hasInstance](x: unknown): x is GlobalStateCls<unknown>;
|
9
|
+
get value(): ValueType;
|
10
|
+
set value(v: ValueType);
|
11
|
+
get hasValue(): boolean;
|
12
|
+
constructor(key?: bytes | string, value?: ValueType);
|
13
|
+
}
|
14
|
+
export declare class LocalStateCls<ValueType> {
|
15
|
+
#private;
|
16
|
+
delete: () => void;
|
17
|
+
get value(): ValueType;
|
18
|
+
set value(v: ValueType);
|
19
|
+
get hasValue(): boolean;
|
20
|
+
}
|
21
|
+
export declare class LocalStateMapCls<ValueType> {
|
22
|
+
#private;
|
23
|
+
getValue(account: Account): LocalStateCls<ValueType>;
|
24
|
+
}
|