iso-filecoin
Version:
Isomorphic filecoin abstractions for RPC, signatures, address, token and wallet
347 lines (346 loc) • 10.7 kB
TypeScript
/**
* Asserts that the given value is an {@link IAddress} instance.
*
* @example
* ```ts twoslash
* import { isAddress, fromString } from 'iso-filecoin/address'
*
* const address = isAddress(fromString('f1...')) // true
* const notAddress = isAddress('f1...') // falseeeeeee
* ```
*
* @param {any} val
* @returns {val is IAddress}
*/
export function isAddress(val: any): val is IAddress;
/**
* Check if object is a {@link AddressSecp256k1} instance
*
* @param {any} val
* @returns {val is AddressSecp256k1}
*/
export function isAddressSecp256k1(val: any): val is AddressSecp256k1;
/**
* Check if object is a {@link AddressBLS} instance
*
* @param {any} val
* @returns {val is AddressBLS}
*/
export function isAddressBls(val: any): val is AddressBLS;
/**
* Check if object is a {@link AddressId} instance
*
* @param {any} val
* @returns {val is AddressId}
*/
export function isAddressId(val: any): val is AddressId;
/**
* Check if object is a {@link AddressDelegated} instance
*
* @param {any} val
* @returns {val is AddressDelegated}
*/
export function isAddressDelegated(val: any): val is AddressDelegated;
/**
* Check if string is valid Ethereum address
*
* Based on viem implementation {@link https://github.com/wevm/viem/blob/main/src/utils/address/isAddress.ts}
*
* @param {string} address
*/
export function isEthAddress(address: string): boolean;
/**
* Checks if address is an Ethereum ID mask address
*
* @param {string} address
*/
export function isIdMaskAddress(address: string): boolean;
/**
* Address from Ethereum address
*
* @param {string} address
* @param {import('./types.js').Network} network
* @returns {IAddress}
*/
export function fromEthAddress(address: string, network: import("./types.js").Network): IAddress;
/**
* Ethereum address from f0 or f4 addresses
*
* @param {IAddress} address
*/
export function toEthAddress(address: IAddress): string;
/**
* @param {Value} value - Value to convert to address
* @param {import('./types.js').Network} [network] - Network
* @returns {IAddress}
*/
export function from(value: Value, network?: import("./types.js").Network): IAddress;
/**
* Address from string
*
* @param {string} address
* @returns {IAddress}
*/
export function fromString(address: string): IAddress;
/**
* Create address from bytes
*
* @param {Uint8Array} bytes
* @param {import('./types.js').Network} network
* @returns {IAddress}
*/
export function fromBytes(bytes: Uint8Array, network: import("./types.js").Network): IAddress;
/**
* Create address from public key bytes
* Only for f1 SECP256K1 and f3 BLS
*
* @param {Uint8Array} bytes
* @param {import('./types.js').Network} network
* @param {import('./types.js').SignatureType} type
* @returns IAddress
*/
export function fromPublicKey(bytes: Uint8Array, network: import("./types.js").Network, type: import("./types.js").SignatureType): AddressSecp256k1 | AddressBLS;
/**
* Create an `Address` instance from a 0x-prefixed hex string address returned by `Address.toContractDestination()`.
*
* @param {`0x${string}`} address - The 0x-prefixed hex string address.
* @param {import("./types.js").Network} network - The network the address is on.
*/
export function fromContractDestination(address: `0x${string}`, network: import("./types.js").Network): import("./types.js").IAddress;
export { checksumEthAddress } from "./utils.js";
export namespace PROTOCOL_INDICATOR {
let ID: 0;
let SECP256K1: 1;
let ACTOR: 2;
let BLS: 3;
let DELEGATED: 4;
}
/**
* ID Address f0..
*
* Protocol 0 addresses are simple IDs. All actors have a numeric ID even if they don’t have public keys. The payload of an ID address is base10 encoded. IDs are not hashed and do not have a checksum.
*
* @see https://spec.filecoin.io/appendix/address/#section-appendix.address.protocol-0-ids
*
* @implements {IAddress}
*/
export class AddressId extends Address implements IAddress {
/**
* Create address from string
*
* @param {string} address
*/
static fromString(address: string): AddressId;
/**
* Create address from bytes
*
* @param {Uint8Array} bytes
* @param {import('./types.js').Network} network
*/
static fromBytes(bytes: Uint8Array, network: import("./types.js").Network): AddressId;
/**
* Create ID address from ID masked 0x address
*
* @param {string} address
* @param {import('./types.js').Network} network
*/
static fromIdMaskAddress(address: string, network: import("./types.js").Network): AddressId;
protocol: 0;
id: bigint;
/**
* Convert address to ID masked 0x address
*
* To convert to an eth address you probably should use {@link to0x}
*/
toIdMaskAddress(): string;
/**
* Get robust address from public key address
*
* @param {AddressRpcOptions} options
*/
toRobust(options: AddressRpcOptions): Promise<import("./types.js").IAddress>;
/**
* @param {AddressRpcOptions} options
*/
to0x(options: AddressRpcOptions): Promise<string>;
}
/**
* Secp256k1 address f1..
*
* @see https://spec.filecoin.io/appendix/address/#section-appendix.address.protocol-1-libsecpk1-elliptic-curve-public-keys
*
* @implements {IAddress}
*/
export class AddressSecp256k1 extends Address implements IAddress {
/**
* Create address from string
*
* @param {string} address
*/
static fromString(address: string): AddressSecp256k1;
/**
* Create address from bytes
*
* @param {Uint8Array} bytes
* @param {import('./types.js').Network} network
* @returns
*/
static fromBytes(bytes: Uint8Array, network: import("./types.js").Network): AddressSecp256k1;
/**
* @param {Uint8Array} publicKey
* @param {import('./types.js').Network} network
*/
static fromPublicKey(publicKey: Uint8Array, network: import("./types.js").Network): AddressSecp256k1;
protocol: 1;
}
/**
* Actor Address f2..
*
* Protocol 2 addresses representing an Actor. The payload field contains the SHA256 hash of meaningful data produced as a result of creating the actor.
*
* @see https://spec.filecoin.io/appendix/address/#section-appendix.address.protocol-2-actor
*
* @implements {IAddress}
*/
export class AddressActor extends Address implements IAddress {
/**
* Create address from string
*
* @param {string} address
*/
static fromString(address: string): AddressActor;
/**
* Create address from bytes
*
* @param {Uint8Array} bytes
* @param {import('./types.js').Network} network
* @returns
*/
static fromBytes(bytes: Uint8Array, network: import("./types.js").Network): AddressActor;
protocol: 2;
}
/**
* BLS Address f3..
*
* Protocol 3 addresses represent BLS public encryption keys. The payload field contains the BLS public key.
*
* @see https://spec.filecoin.io/appendix/address/#section-appendix.address.protocol-3-bls
*
* @implements {IAddress}
*/
export class AddressBLS extends Address implements IAddress {
/**
* Create address from string
*
* @param {string} address
*/
static fromString(address: string): AddressBLS;
/**
* Create address from bytes
*
* @param {Uint8Array} bytes
* @param {import('./types.js').Network} network
* @returns
*/
static fromBytes(bytes: Uint8Array, network: import("./types.js").Network): AddressBLS;
/**
*
* @param {Uint8Array} publicKey
* @param {import('./types.js').Network} network
*/
static fromPublicKey(publicKey: Uint8Array, network: import("./types.js").Network): AddressBLS;
protocol: 3;
}
/**
* Delegated address f4..
*
* @see https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0048.md
*
* @implements {IAddress}
*/
export class AddressDelegated extends Address implements IAddress {
/**
* Create address from string
*
* @param {string} address
*/
static fromString(address: string): AddressDelegated;
/**
* Create address from bytes
*
* @param {Uint8Array} bytes
* @param {import('./types.js').Network} network
* @returns
*/
static fromBytes(bytes: Uint8Array, network: import("./types.js").Network): AddressDelegated;
/**
* Create delegated address from ethereum address
*
* @param {string} address
* @param {import('./types.js').Network} network
*/
static fromEthAddress(address: string, network: import("./types.js").Network): AddressDelegated;
/**
* @param {number} namespace
* @param {Uint8Array} payload
* @param {import("./types.js").Network} network
*/
constructor(namespace: number, payload: Uint8Array, network: import("./types.js").Network);
protocol: 4;
namespace: number;
/**
* Convert address to ethereum address
*
* @param {AddressRpcOptions} _rpc
* @returns {Promise<string>}
*/
to0x(_rpc: AddressRpcOptions): Promise<string>;
/**
* Converts to 0x eth address, it's similar to {@link to0x} but sync
* because f4s dont need to check the chain to get the address
*
*/
toEthAddress(): string;
}
export type IAddress = import("./types.js").IAddress;
export type Value = string | IAddress | BufferSource;
/**
* Generic address class
*
* @implements {IAddress}
*/
declare class Address implements IAddress {
/**
*
* @param {Uint8Array} payload
* @param {import("./types.js").Network} network
*/
constructor(payload: Uint8Array, network: import("./types.js").Network);
payload: Uint8Array<ArrayBufferLike>;
network: import("./types.js").Network;
networkPrefix: "f" | "t";
/** @type {import('./types.js').ProtocolIndicatorCode} */
protocol: import("./types.js").ProtocolIndicatorCode;
toString(): string;
toBytes(): Uint8Array<ArrayBuffer>;
toContractDestination(): `0x${string}`;
checksum(): Uint8Array<ArrayBufferLike>;
/**
* @inheritdoc IAddress.toIdAddress
* @param {AddressRpcSafetyOptions} options
* @returns {Promise<AddressId>}
*/
toIdAddress(options: AddressRpcSafetyOptions): Promise<AddressId>;
/**
* @inheritdoc IAddress.to0x
* @param {AddressRpcSafetyOptions} options
* @returns {Promise<string>}
*/
to0x(options: AddressRpcSafetyOptions): Promise<string>;
/** @type {boolean} */
[symbol]: boolean;
}
import type { AddressRpcOptions } from './types.js';
import type { AddressRpcSafetyOptions } from './types.js';
declare const symbol: unique symbol;
//# sourceMappingURL=address.d.ts.map