@asichain/asi-wallet-sdk 0.1.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.
Files changed (43) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +330 -0
  3. package/dist/config/index.d.ts +15 -0
  4. package/dist/domains/Asset/index.d.ts +12 -0
  5. package/dist/domains/BlockchainGateway/index.d.ts +48 -0
  6. package/dist/domains/BrowserStorage/index.d.ts +21 -0
  7. package/dist/domains/Client/index.d.ts +16 -0
  8. package/dist/domains/Deploy/factory/index.d.ts +4 -0
  9. package/dist/domains/Deploy/index.d.ts +8 -0
  10. package/dist/domains/EncryptedRecord/index.d.ts +10 -0
  11. package/dist/domains/Error/DeploymentErrorHandler.d.ts +8 -0
  12. package/dist/domains/Error/index.d.ts +2 -0
  13. package/dist/domains/Error/meta.d.ts +21 -0
  14. package/dist/domains/HttpClient/index.d.ts +13 -0
  15. package/dist/domains/Signer/index.d.ts +12 -0
  16. package/dist/domains/Vault/index.d.ts +41 -0
  17. package/dist/domains/Wallet/index.d.ts +58 -0
  18. package/dist/domains/index.d.ts +15 -0
  19. package/dist/index.cjs.js +1 -0
  20. package/dist/index.d.ts +504 -0
  21. package/dist/index.esm.js +1 -0
  22. package/dist/services/AssetsService/index.d.ts +6 -0
  23. package/dist/services/BinaryWriter/index.d.ts +8 -0
  24. package/dist/services/Crypto/index.d.ts +29 -0
  25. package/dist/services/Fee/index.d.ts +5 -0
  26. package/dist/services/KeyDerivation/index.d.ts +15 -0
  27. package/dist/services/KeysManager/index.d.ts +14 -0
  28. package/dist/services/Mnemonic/index.d.ts +11 -0
  29. package/dist/services/Resubmit/DeployResubmitter.d.ts +22 -0
  30. package/dist/services/Resubmit/NodeManager.d.ts +22 -0
  31. package/dist/services/Resubmit/index.d.ts +3 -0
  32. package/dist/services/Resubmit/types.d.ts +32 -0
  33. package/dist/services/Signer/index.d.ts +5 -0
  34. package/dist/services/Transfer/index.d.ts +11 -0
  35. package/dist/services/Wallets/index.d.ts +16 -0
  36. package/dist/services/index.d.ts +19 -0
  37. package/dist/utils/codec/index.d.ts +6 -0
  38. package/dist/utils/constants/index.d.ts +24 -0
  39. package/dist/utils/functions/index.d.ts +5 -0
  40. package/dist/utils/index.d.ts +5 -0
  41. package/dist/utils/polyfills/index.d.ts +1 -0
  42. package/dist/utils/validators/index.d.ts +21 -0
  43. package/package.json +53 -0
@@ -0,0 +1,11 @@
1
+ export declare enum MnemonicStrength {
2
+ TWELVE_WORDS = 128,
3
+ TWENTY_FOUR_WORDS = 256
4
+ }
5
+ export default class MnemonicService {
6
+ static generateMnemonic(strength?: MnemonicStrength): string;
7
+ static generateMnemonicArray(strength?: MnemonicStrength): string[];
8
+ static isMnemonicValid(mnemonic: string): boolean;
9
+ static mnemonicToWordArray(mnemonic: string): string[];
10
+ static wordArrayToMnemonic(words: string[]): string;
11
+ }
@@ -0,0 +1,22 @@
1
+ import { ResubmitConfig, ResubmitResult } from "./types";
2
+ import Wallet from "@domains/Wallet";
3
+ import { PasswordProvider } from "@domains/Signer";
4
+ export default class DeployResubmitter {
5
+ private readonly config;
6
+ private readonly nodeManager;
7
+ private readonly errorHandler;
8
+ private startSubmissionTime;
9
+ constructor(config: ResubmitConfig, availableNodesUrls: string[]);
10
+ private isDeployExpired;
11
+ private sleep;
12
+ private retryDeployToOneNode;
13
+ private retryDeployToRandomNodes;
14
+ private pollDeployStatus;
15
+ /**
16
+
17
+ * Main resubmit function
18
+ * Executes the complete resubmit algorithm for deploy
19
+ * NOT FOR "READ-ONLY" DEPLOYS (exploratory deploys)
20
+ */
21
+ resubmit(rholangCode: string, wallet: Wallet, passwordProvider: PasswordProvider, phloLimit?: number): Promise<ResubmitResult>;
22
+ }
@@ -0,0 +1,22 @@
1
+ import { NodeProvider } from "./types";
2
+ export default class NodeManager implements NodeProvider {
3
+ private static instance;
4
+ private retriesLeft;
5
+ private readonly availableNodesUrls;
6
+ private readonly useRandomNode;
7
+ private readonly inactiveNodesUrls;
8
+ private currentNodeUrl;
9
+ private constructor();
10
+ static initialize(availableNodesUrls: string[], nodeSelectionAttempts?: number, useRandomNode?: boolean): NodeManager;
11
+ connectDefaultNode(): Promise<void>;
12
+ private connectNode;
13
+ static getInstance(): NodeManager;
14
+ isInitialized(): boolean;
15
+ private markNodeInactive;
16
+ deactivateCurrentNode(): void;
17
+ private deactivateNode;
18
+ private getAvailableNodesUrls;
19
+ getRetriesLeft(): number;
20
+ private getRandomAvailableNodeUrl;
21
+ connectActiveRandomNode(): Promise<void>;
22
+ }
@@ -0,0 +1,3 @@
1
+ export { default } from "./DeployResubmitter";
2
+ export { default as ResubmitNodeManager } from "./NodeManager";
3
+ export { type ResubmitConfig, type ResubmitResult, } from "./types";
@@ -0,0 +1,32 @@
1
+ import { DeploymentErrorType, FatalDeployErrors, RecoverableDeployErrors, DeploymentErrorHandler } from "@domains/Error";
2
+ import BlockchainGateway, { type DeployStatusResult, DeployStatus } from '@domains/BlockchainGateway';
3
+ export { DeployStatus, DeployStatusResult, DeploymentErrorHandler, RecoverableDeployErrors, FatalDeployErrors, BlockchainGateway };
4
+ export interface NodeProvider {
5
+ connectDefaultNode(): Promise<void>;
6
+ connectActiveRandomNode(): Promise<void>;
7
+ deactivateCurrentNode(): void;
8
+ isInitialized(): boolean;
9
+ getRetriesLeft(): number;
10
+ }
11
+ export interface ResubmitConfig {
12
+ phloPrice: number;
13
+ useRandomNode: boolean;
14
+ deployValiditySeconds: number;
15
+ nodeSelectionAttempts: number;
16
+ deployRetries: number;
17
+ deployIntervalSeconds: number;
18
+ pollingIntervalSeconds: number;
19
+ }
20
+ export interface ErrorDetail {
21
+ blockchainError?: {
22
+ type: DeploymentErrorType;
23
+ message: string;
24
+ };
25
+ exceededTimeout?: FatalDeployErrors.DEPLOY_SUBMIT_TIMEOUT | FatalDeployErrors.BLOCK_INCLUSION_TIMEOUT;
26
+ }
27
+ export interface ResubmitResult {
28
+ success: boolean;
29
+ deployId?: string;
30
+ deployStatus?: DeployStatus;
31
+ error?: ErrorDetail;
32
+ }
@@ -0,0 +1,5 @@
1
+ import { SigningRequest, PasswordProvider, SignedResult } from "@domains/Signer";
2
+ export default class SignerService {
3
+ static sign(request: SigningRequest, passwordProvider: PasswordProvider): Promise<SignedResult>;
4
+ private static readonly deployDataProtobufSerialize;
5
+ }
@@ -0,0 +1,11 @@
1
+ import Wallet, { Address } from "@domains/Wallet";
2
+ import { PasswordProvider } from "@domains/Signer";
3
+ export default class AssetsService {
4
+ transfer(fromAddress: string, toAddress: string, amount: bigint, wallet: Wallet, passwordProvider: PasswordProvider, phloLimit?: number): Promise<string | undefined>;
5
+ /**
6
+ * Get ASI token balance for an address
7
+ * @param address The address to check balance for
8
+ * @returns Balance in smallest units (bigint)
9
+ */
10
+ getASIBalance(address: Address): Promise<bigint>;
11
+ }
@@ -0,0 +1,16 @@
1
+ import { Address } from "@domains/Wallet";
2
+ export interface CreateWalletOptions {
3
+ name?: string;
4
+ }
5
+ export interface WalletMeta {
6
+ address: string;
7
+ privateKey: Uint8Array;
8
+ publicKey?: Uint8Array;
9
+ mnemonic?: string;
10
+ }
11
+ export default class WalletsService {
12
+ static createWallet(privateKey?: Uint8Array, options?: CreateWalletOptions): WalletMeta;
13
+ static createWalletFromMnemonic(mnemonic?: string, index?: number): Promise<WalletMeta>;
14
+ static deriveAddressFromPrivateKey(privateKey: Uint8Array): Address;
15
+ static deriveAddressFromPublicKey(publicKey: Uint8Array): Address;
16
+ }
@@ -0,0 +1,19 @@
1
+ export * from "./Fee";
2
+ export * from "./Crypto";
3
+ export * from "./Wallets";
4
+ export * from "./Mnemonic";
5
+ export * from "./KeysManager";
6
+ export * from "./KeyDerivation";
7
+ export * from "./Resubmit";
8
+ export * from "./Signer";
9
+ export * from "./AssetsService";
10
+ export { default as KeyDerivationService } from "./KeyDerivation";
11
+ export { default as BinaryWriter } from "./BinaryWriter";
12
+ export { default as MnemonicService } from "./Mnemonic";
13
+ export { default as KeysManager } from "./KeysManager";
14
+ export { default as WalletsService } from "./Wallets";
15
+ export { default as CryptoService } from "./Crypto";
16
+ export { default as FeeService } from "./Fee";
17
+ export { default as DeployResubmitter } from "./Resubmit";
18
+ export { default as SignerService } from "./Signer";
19
+ export { default as AssetsService } from "./AssetsService";
@@ -0,0 +1,6 @@
1
+ export declare const encodeBase58: (hex: string) => string;
2
+ export declare const decodeBase58: (value: string) => Uint8Array;
3
+ export declare const decodeBase16: (hex: string) => Uint8Array;
4
+ export declare const encodeBase16: (bytes: Uint8Array) => string;
5
+ export declare const arrayBufferToBase64: (buffer: ArrayBuffer) => string;
6
+ export declare const base64ToArrayBuffer: (base64: string) => ArrayBuffer;
@@ -0,0 +1,24 @@
1
+ export declare const PRIVATE_KEY_LENGTH = 32;
2
+ export declare const ASI_CHAIN_PREFIX: {
3
+ coinId: string;
4
+ version: string;
5
+ };
6
+ export declare const ASI_COIN_TYPE = 60;
7
+ export declare const ASI_DECIMALS = 8;
8
+ export declare const GasFee: {
9
+ BASE_FEE: number;
10
+ VARIATION_RANGE: number;
11
+ LABEL: string;
12
+ TRANSFER: string;
13
+ DEPLOY: string;
14
+ };
15
+ export declare const POWER_BASE: number;
16
+ export declare const ASI_BASE_UNIT: bigint;
17
+ export declare const FAULT_TOLERANCE_THRESHOLD: number;
18
+ export declare const INVALID_BLOCK_NUMBER = -1;
19
+ export declare const DEFAULT_BIP_44_PATH_OPTIONS: {
20
+ coinType: number;
21
+ account: number;
22
+ change: number;
23
+ index: number;
24
+ };
@@ -0,0 +1,5 @@
1
+ export declare const toAtomicAmount: (amount: number | string) => bigint;
2
+ export declare const fromAtomicAmountToString: (atomicAmount: bigint) => string;
3
+ export declare const fromAtomicAmountToNumber: (atomicAmount: bigint) => number;
4
+ export declare const fromAtomicAmount: (atomicAmount: bigint) => string;
5
+ export declare const genRandomHex: (size: number) => string;
@@ -0,0 +1,5 @@
1
+ export * from "./codec";
2
+ export * from "./constants";
3
+ export * from "./functions";
4
+ export * from "./polyfills";
5
+ export * from "./validators";
@@ -0,0 +1 @@
1
+ export declare const setupBufferPolyfill: () => void;
@@ -0,0 +1,21 @@
1
+ import type { Address } from "@domains/Wallet";
2
+ export declare const validateAccountName: (name: string, maxLength?: number) => {
3
+ isValid: boolean;
4
+ error?: string;
5
+ };
6
+ export declare enum AddressValidationErrorCode {
7
+ INVALID_PREFIX = "INVALID_PREFIX",
8
+ INVALID_LENGTH = "INVALID_LENGTH",
9
+ INVALID_ALPHABET = "INVALID_ALPHABET",
10
+ INVALID_BASE58 = "INVALID_BASE58",
11
+ INVALID_HEX_LENGTH = "INVALID_HEX_LENGTH",
12
+ INVALID_CHAIN_PREFIX = "INVALID_CHAIN_PREFIX",
13
+ INVALID_CHECKSUM = "INVALID_CHECKSUM",
14
+ NON_CANONICAL = "NON_CANONICAL"
15
+ }
16
+ export interface AddressValidationResult {
17
+ isValid: boolean;
18
+ errorCode?: AddressValidationErrorCode;
19
+ }
20
+ export declare const validateAddress: (address: string) => AddressValidationResult;
21
+ export declare const isAddress: (address: string) => address is Address;
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "version": "0.1.0",
3
+ "name": "@asichain/asi-wallet-sdk",
4
+ "description": "ASI Wallet SDK",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "dist/index.cjs.js",
8
+ "module": "dist/index.esm.js",
9
+ "types": "dist/index.d.ts",
10
+ "sideEffects": false,
11
+ "files": [
12
+ "dist",
13
+ "README.md"
14
+ ],
15
+ "scripts": {
16
+ "dev": "tsc -p tsconfig.build.json --emitDeclarationOnly && rollup -c -w",
17
+ "build": "tsc -p tsconfig.build.json --emitDeclarationOnly && rollup -c",
18
+ "test:security": "node scripts/security/run-security-tests.mjs",
19
+ "check:secret-logs": "node scripts/security/check-secret-logs.mjs",
20
+ "security:gate": "npm run build && npm run test:security && npm run check:secret-logs && npm audit --omit=dev"
21
+ },
22
+ "devDependencies": {
23
+ "@rollup/plugin-alias": "^5.0.0",
24
+ "@rollup/plugin-commonjs": "^25.0.0",
25
+ "@rollup/plugin-node-resolve": "^15.0.1",
26
+ "@rollup/plugin-terser": "^0.1.0",
27
+ "@rollup/plugin-typescript": "^11.1.0",
28
+ "@types/node": "^25.4.0",
29
+ "rollup": "^3.27.0",
30
+ "rollup-plugin-dts": "^6.3.0",
31
+ "tsx": "^4.20.6",
32
+ "tslib": "^2.8.1",
33
+ "typescript": "^5.9.3"
34
+ },
35
+ "dependencies": {
36
+ "@noble/hashes": "^1.6.0",
37
+ "@noble/secp256k1": "^1.7.0",
38
+ "axios": "^1.13.2",
39
+ "bip32": "^4.0.0",
40
+ "bip39": "^3.1.0",
41
+ "blakejs": "^1.2.1",
42
+ "bs58": "^6.0.0",
43
+ "buffer": "^6.0.3",
44
+ "js-sha3": "^0.9.3",
45
+ "tiny-secp256k1": "^2.2.4"
46
+ },
47
+ "exports": {
48
+ ".": {
49
+ "import": "./dist/index.esm.js",
50
+ "require": "./dist/index.cjs.js"
51
+ }
52
+ }
53
+ }