diff --git a/types/stellar-base/index.d.ts b/types/stellar-base/index.d.ts new file mode 100644 index 0000000000..a230c36942 --- /dev/null +++ b/types/stellar-base/index.d.ts @@ -0,0 +1,502 @@ +// Type definitions for stellar-base 0.10 +// Project: https://github.com/stellar/js-stellar-sdk +// Definitions by: Carl Foster +// Triston Jones +// Paul Selden +// Max Bause +// Timur Ramazanov +// Kalvis Kalniņš +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.9 + +/// +export {}; + +export class Account { + constructor(accountId: string, sequence: string | number) + accountId(): string; + sequenceNumber(): string; + incrementSequenceNumber(): void; +} + +export namespace AssetType { + type native = 'native'; + type credit4 = 'credit_alphanum4'; + type credit12 = 'credit_alphanum12'; +} +export type AssetType = + | AssetType.native + | AssetType.credit4 + | AssetType.credit12 +; + +export class Asset { + static native(): Asset; + static fromOperation(xdr: xdr.Asset): Asset; + + constructor(code: string, issuer: string); + + getCode(): string; + getIssuer(): string; + getAssetType(): AssetType; + isNative(): boolean; + equals(other: Asset): boolean; + toXDRObject(): xdr.Asset; + + code: string; + issuer: string; +} + +export const FastSigning: boolean; + +export class Keypair { + static fromRawEd25519Seed(secretSeed: Buffer): Keypair; + static fromBase58Seed(secretSeed: string): Keypair; + static fromSecret(secretKey: string): Keypair; + static master(): Keypair; + static fromPublicKey(publicKey: string): Keypair; + static random(): Keypair; + + constructor(keys: { type: 'ed25519', secretKey: string } | { type: 'ed25519', Key: string }) + + publicKey(): string; + secret(): string; + rawPublicKey(): Buffer; + rawSecretKey(): Buffer; + canSign(): boolean; + sign(data: Buffer): Buffer; + signDecorated(data: Buffer): xdr.DecoratedSignature; + signatureHint(): xdr.SignatureHint; + verify(data: Buffer, signature: Buffer): boolean; +} + +export const MemoNone = 'none'; +export const MemoID = 'id'; +export const MemoText = 'text'; +export const MemoHash = 'hash'; +export const MemoReturn = 'return'; +export namespace MemoType { + type None = typeof MemoNone; + type ID = typeof MemoID; + type Text = typeof MemoText; + type Hash = typeof MemoHash; + type Return = typeof MemoReturn; +} +export type MemoType = + | MemoType.None + | MemoType.ID + | MemoType.Text + | MemoType.Hash + | MemoType.Return +; +export type MemoValue = null | string | Buffer; + +export class Memo { + static fromXDRObject(memo: xdr.Memo): Memo; + static hash(hash: string): Memo; + static id(id: string): Memo; + static none(): Memo; + static return(hash: string): Memo; + static text(text: string): Memo; + + constructor(type: MemoType.None, value?: null); + constructor(type: MemoType.Hash | MemoType.Return, value: Buffer) + constructor(type: MemoType.Hash | MemoType.Return | MemoType.ID | MemoType.Text, value: string) + constructor(type: T, value: MemoValue) + + type: T; + value: + T extends MemoType.None ? null : + T extends MemoType.ID ? string : + T extends MemoType.Text ? string | Buffer : // github.com/stellar/js-stellar-base/issues/152 + T extends MemoType.Hash ? Buffer : + T extends MemoType.Return ? Buffer : + MemoValue; + + toXDRObject(): xdr.Memo; +} + +export enum Networks { + PUBLIC = 'Public Global Stellar Network ; September 2015', + TESTNET = 'Test SDF Network ; September 2015', +} + +export class Network { + static use(network: Network): void; + static usePublicNetwork(): void; + static useTestNetwork(): void; + static current(): Network; + + constructor(passphrase: string) + + networkPassphrase(): string; + networkId(): string; +} + +export const AuthRequiredFlag: 1; +export const AuthRevocableFlag: 2; +export const AuthImmutableFlag: 4; +export namespace AuthFlag { + type required = typeof AuthRequiredFlag; + type revocable = typeof AuthRevocableFlag; + type rmmutable = typeof AuthImmutableFlag; +} +export type AuthFlag = + | AuthFlag.required + | AuthFlag.revocable + | AuthFlag.rmmutable +; + +export namespace Signer { + interface Ed25519PublicKey { + ed25519PublicKey: string; + weight: number | undefined; + } + interface Sha256Hash { + sha256Hash: Buffer; + weight: number | undefined; + } + interface PreAuthTx { + preAuthTx: Buffer; + weight: number | undefined; + } +} +export type Signer = + | Signer.Ed25519PublicKey + | Signer.Sha256Hash + | Signer.PreAuthTx +; + +export namespace SignerOptions { + interface Ed25519PublicKey { + ed25519PublicKey: string; + weight?: number | string; + } + interface Sha256Hash { + sha256Hash: Buffer | string; + weight?: number | string; + } + interface PreAuthTx { + preAuthTx: Buffer | string; + weight?: number | string; + } +} +export type SignerOptions = + | SignerOptions.Ed25519PublicKey + | SignerOptions.Sha256Hash + | SignerOptions.PreAuthTx +; + +export namespace OperationType { + type CreateAccount = 'createAccount'; + type Payment = 'payment'; + type PathPayment = 'pathPayment'; + type CreatePassiveOffer = 'createPassiveOffer'; + type ManageOffer = 'manageOffer'; + type SetOptions = 'setOptions'; + type ChangeTrust = 'changeTrust'; + type AllowTrust = 'allowTrust'; + type AccountMerge = 'accountMerge'; + type Inflation = 'inflation'; + type ManageData = 'manageData'; + type BumpSequence = 'bumpSequence'; +} +export type OperationType = + | OperationType.CreateAccount + | OperationType.Payment + | OperationType.PathPayment + | OperationType.CreatePassiveOffer + | OperationType.ManageOffer + | OperationType.SetOptions + | OperationType.ChangeTrust + | OperationType.AllowTrust + | OperationType.AccountMerge + | OperationType.Inflation + | OperationType.ManageData + | OperationType.BumpSequence +; + +export namespace OperationOptions { + interface BaseOptions { + source?: string; + } + interface AccountMerge extends BaseOptions { + destination: string; + } + interface AllowTrust extends BaseOptions { + trustor: string; + assetCode: string; + authorize?: boolean; + } + interface ChangeTrust extends BaseOptions { + asset: Asset; + limit?: string; + } + interface CreateAccount extends BaseOptions { + destination: string; + startingBalance: string; + } + interface CreatePassiveOffer extends BaseOptions { + selling: Asset; + buying: Asset; + amount: string; + price: number | string | object /* bignumber.js */; + } + interface ManageOffer extends CreatePassiveOffer { + offerId?: number | string; + } + interface Inflation extends BaseOptions { // tslint:disable-line + } + interface ManageData extends BaseOptions { + name: string; + value: string | Buffer; + } + interface PathPayment extends BaseOptions { + sendAsset: Asset; + sendMax: string; + destination: string; + destAsset: Asset; + destAmount: string; + path?: Asset[]; + } + interface Payment extends BaseOptions { + amount: string; + asset: Asset; + destination: string; + } + interface SetOptions extends BaseOptions { + inflationDest?: string; + clearFlags?: AuthFlag; + setFlags?: AuthFlag; + masterWeight?: number | string; + lowThreshold?: number | string; + medThreshold?: number | string; + highThreshold?: number | string; + homeDomain?: string; + signer?: T; + } + interface BumpSequence extends BaseOptions { + bumpTo: string; + } +} +export type OperationOptions = + | OperationOptions.CreateAccount + | OperationOptions.Payment + | OperationOptions.PathPayment + | OperationOptions.CreatePassiveOffer + | OperationOptions.ManageOffer + | OperationOptions.SetOptions + | OperationOptions.ChangeTrust + | OperationOptions.AllowTrust + | OperationOptions.AccountMerge + | OperationOptions.Inflation + | OperationOptions.ManageData + | OperationOptions.BumpSequence +; + +export namespace Operation { + interface BaseOperation { + type: T; + source?: string; + } + + interface AccountMerge extends BaseOperation { + destination: string; + } + function accountMerge(options: OperationOptions.AccountMerge): xdr.Operation; + + interface AllowTrust extends BaseOperation { + trustor: string; + assetCode: string; + authorize: boolean | undefined; + } + function allowTrust(options: OperationOptions.AllowTrust): xdr.Operation; + + interface ChangeTrust extends BaseOperation { + line: Asset; + limit: string; + } + function changeTrust(options: OperationOptions.ChangeTrust): xdr.Operation; + + interface CreateAccount extends BaseOperation { + destination: string; + startingBalance: string; + } + function createAccount(options: OperationOptions.CreateAccount): xdr.Operation; + + interface CreatePassiveOffer extends BaseOperation { + selling: Asset; + buying: Asset; + amount: string; + price: string; + } + function createPassiveOffer(options: OperationOptions.CreatePassiveOffer): xdr.Operation; + + interface Inflation extends BaseOperation { + } + function inflation(options: OperationOptions.Inflation): xdr.Operation; + + interface ManageData extends BaseOperation { + name: string; + value: Buffer; + } + function manageData(options: OperationOptions.ManageData): xdr.Operation; + + interface ManageOffer extends BaseOperation { + selling: Asset; + buying: Asset; + amount: string; + price: string; + offerId: string; + } + function manageOffer(options: OperationOptions.ManageOffer): xdr.Operation; + + interface PathPayment extends BaseOperation { + sendAsset: Asset; + sendMax: string; + destination: string; + destAsset: Asset; + destAmount: string; + path: Asset[]; + } + function pathPayment(options: OperationOptions.PathPayment): xdr.Operation; + + interface Payment extends BaseOperation { + amount: string; + asset: Asset; + destination: string; + } + function payment(options: OperationOptions.Payment): xdr.Operation; + + interface SetOptions extends BaseOperation { + inflationDest?: string; + clearFlags?: AuthFlag; + setFlags?: AuthFlag; + masterWeight?: number; + lowThreshold?: number; + medThreshold?: number; + highThreshold?: number; + homeDomain?: string; + signer: + T extends {ed25519PublicKey: any} ? Signer.Ed25519PublicKey : + T extends {sha256Hash: any} ? Signer.Sha256Hash : + T extends {preAuthTx: any} ? Signer.PreAuthTx : + never; + } + function setOptions(options: OperationOptions.SetOptions): xdr.Operation>; + + interface BumpSequence extends BaseOperation { + bumpTo: string; + } + function bumpSequence(options: OperationOptions.BumpSequence): xdr.Operation; + + function fromXDRObject(xdrOperation: xdr.Operation): T; +} +export type Operation = + Operation.CreateAccount + | Operation.Payment + | Operation.PathPayment + | Operation.CreatePassiveOffer + | Operation.ManageOffer + | Operation.SetOptions + | Operation.ChangeTrust + | Operation.AllowTrust + | Operation.AccountMerge + | Operation.Inflation + | Operation.ManageData + | Operation.BumpSequence +; + +export namespace StrKey { + function encodeEd25519PublicKey(data: Buffer): string; + function decodeEd25519PublicKey(data: string): Buffer; + function isValidEd25519PublicKey(Key: string): boolean; + + function encodeEd25519SecretSeed(data: Buffer): string; + function decodeEd25519SecretSeed(data: string): Buffer; + function isValidEd25519SecretSeed(seed: string): boolean; + + function encodePreAuthTx(data: Buffer): string; + function decodePreAuthTx(data: string): Buffer; + + function encodeSha256Hash(data: Buffer): string; + function decodeSha256Hash(data: string): Buffer; +} + +export class Transaction { + constructor(envelope: string | xdr.TransactionEnvelope) + hash(): Buffer; + sign(...keypairs: Keypair[]): void; + signatureBase(): Buffer; + signHashX(preimage: Buffer | string): void; + toEnvelope(): xdr.TransactionEnvelope; + + operations: TOps; + sequence: number; + fee: number; + source: string; + memo: TMemo; + signatures: xdr.DecoratedSignature[]; +} + +export class TransactionBuilder { + constructor(sourceAccount: Account, options?: TransactionBuilder.TransactionBuilderOptions) + addOperation(operation: xdr.Operation): this; + addMemo(memo: Memo): this; + build(): Transaction; +} + +export namespace TransactionBuilder { + interface TransactionBuilderOptions { + fee?: number; + timebounds?: { + minTime?: number | string + maxTime?: number | string + }; + memo?: Memo; + } +} + +// Hidden namespace as hack to work around name collision. +declare namespace xdrHidden { // tslint:disable-line:strict-export-declare-modifiers + class Operation2 extends xdr.XDRStruct { + static fromXDR(xdr: Buffer): xdr.Operation; + } +} + +export namespace xdr { + class XDRStruct { + static fromXDR(xdr: Buffer): XDRStruct; + + toXDR(base?: string): Buffer; + toXDR(encoding: string): string; + } + export import Operation = xdrHidden.Operation2; // tslint:disable-line:strict-export-declare-modifiers + class Asset extends XDRStruct { + static fromXDR(xdr: Buffer): Asset; + } + class Memo extends XDRStruct { + static fromXDR(xdr: Buffer): Memo; + } + class TransactionEnvelope extends XDRStruct { + static fromXDR(xdr: Buffer): TransactionEnvelope; + } + class DecoratedSignature extends XDRStruct { + static fromXDR(xdr: Buffer): DecoratedSignature; + + constructor(keys: { hint: SignatureHint, signature: Signature }) + + hint(): SignatureHint; + signature(): Buffer; + } + type SignatureHint = Buffer; + type Signature = Buffer; + + class TransactionResult extends XDRStruct { + static fromXDR(xdr: Buffer): TransactionResult; + } +} + +export function hash(data: Buffer): Buffer; +export function sign(data: Buffer, rawSecret: Buffer): Buffer; +export function verify(data: Buffer, signature: Buffer, rawPublicKey: Buffer): boolean; diff --git a/types/stellar-base/stellar-base-tests.ts b/types/stellar-base/stellar-base-tests.ts new file mode 100644 index 0000000000..83a52cbe7b --- /dev/null +++ b/types/stellar-base/stellar-base-tests.ts @@ -0,0 +1,40 @@ +import * as StellarSdk from 'stellar-base'; + +const sourceKey = StellarSdk.Keypair.random(); // $ExpectType Keypair +const destKey = StellarSdk.Keypair.random(); +const account = new StellarSdk.Account(sourceKey.publicKey(), '1'); +const transaction = new StellarSdk.TransactionBuilder(account) + .addOperation(StellarSdk.Operation.accountMerge({destination: destKey.publicKey()})) + .addMemo(new StellarSdk.Memo(StellarSdk.MemoText, "memo")) + .build(); // $ExpectType () => Transaction, Operation[]> + +const sig = StellarSdk.xdr.DecoratedSignature.fromXDR(Buffer.of(1, 2)); // $ExpectType DecoratedSignature +sig.hint(); // $ExpectType Buffer +sig.signature(); // $ExpectType Buffer + +StellarSdk.Memo.none(); // $ExpectType Memo<"none"> +StellarSdk.Memo.text('asdf'); // $ExpectType Memo<"text"> +StellarSdk.Memo.id('asdf'); // $ExpectType Memo<"id"> +StellarSdk.Memo.return('asdf'); // $ExpectType Memo<"return"> +StellarSdk.Memo.hash('asdf'); // $ExpectType Memo<"hash"> +StellarSdk.Memo.none().value; // $ExpectType null +StellarSdk.Memo.id('asdf').value; // $ExpectType string +StellarSdk.Memo.text('asdf').value; // $ExpectType string | Buffer +StellarSdk.Memo.return('asdf').value; // $ExpectType Buffer +StellarSdk.Memo.hash('asdf').value; // $ExpectType Buffer + +// P.S. don't use Memo constructor +(new StellarSdk.Memo(StellarSdk.MemoHash, 'asdf')).value; // $ExpectType MemoValue +// (new StellarSdk.Memo(StellarSdk.MemoHash, 'asdf')).type; // $ExpectType MemoType // TODO: Inspect what's wrong with linter. + +const noSignerXDR = StellarSdk.Operation.setOptions({lowThreshold: 1}); +StellarSdk.Operation.fromXDRObject(noSignerXDR).signer; // $ExpectType never + +const newSignerXDR1 = StellarSdk.Operation.setOptions({signer: {ed25519PublicKey: sourceKey.publicKey(), weight: '1'}}); +StellarSdk.Operation.fromXDRObject(newSignerXDR1).signer; // $ExpectType Ed25519PublicKey + +const newSignerXDR2 = StellarSdk.Operation.setOptions({signer: {sha256Hash: Buffer.from(''), weight: '1'}}); +StellarSdk.Operation.fromXDRObject(newSignerXDR2).signer; // $ExpectType Sha256Hash + +const newSignerXDR3 = StellarSdk.Operation.setOptions({signer: {preAuthTx: '', weight: 1}}); +StellarSdk.Operation.fromXDRObject(newSignerXDR3).signer; // $ExpectType PreAuthTx diff --git a/types/stellar-base/tsconfig.json b/types/stellar-base/tsconfig.json new file mode 100644 index 0000000000..ea8f34b1d4 --- /dev/null +++ b/types/stellar-base/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "stellar-base-tests.ts" + ] +} diff --git a/types/stellar-base/tslint.json b/types/stellar-base/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/stellar-base/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/stellar-sdk/index.d.ts b/types/stellar-sdk/index.d.ts index 82ee2f583e..cf05b3412d 100644 --- a/types/stellar-sdk/index.d.ts +++ b/types/stellar-sdk/index.d.ts @@ -7,463 +7,52 @@ // Timur Ramazanov // Kalvis Kalniņš // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 2.9 /// -export namespace StellarBase { - class Account { - constructor(accountId: string, sequence: string | number) - accountId(): string; - sequenceNumber(): string; - incrementSequenceNumber(): void; - } - - enum ASSET_TYPE { - native = 'native', - credit4 = 'credit_alphanum4', - credit12 = 'credit_alphanum12', - } - class Asset { - static native(): Asset; - static fromOperation(xdr: xdr.Asset): Asset; - - constructor(code: string, issuer: string); - - getCode(): string; - getIssuer(): string; - getAssetType(): ASSET_TYPE; - isNative(): boolean; - equals(other: Asset): boolean; - toXDRObject(): xdr.Asset; - - code: string; - issuer: string; - } - - const FastSigning: boolean; - - class Keypair { - static fromRawEd25519Seed(secretSeed: Buffer): Keypair; - static fromBase58Seed(secretSeed: string): Keypair; - static fromSecret(secretKey: string): Keypair; - static master(): Keypair; - static fromPublicKey(publicKey: string): Keypair; - static random(): Keypair; - - constructor(keys: { type: 'ed25519', secretKey: string } | { type: 'ed25519', Key: string }) - - publicKey(): string; - secret(): string; - rawPublicKey(): Buffer; - rawSecretKey(): Buffer; - canSign(): boolean; - sign(data: Buffer): Buffer; - signDecorated(data: Buffer): xdr.DecoratedSignature; - signatureHint(): xdr.SignatureHint; - verify(data: Buffer, signature: Buffer): boolean; - } - - const MemoNone = 'none'; - const MemoID = 'id'; - const MemoText = 'text'; - const MemoHash = 'hash'; - const MemoReturn = 'return'; - type MemoNone = 'none'; - type MemoID = 'id'; - type MemoText = 'text'; - type MemoHash = 'hash'; - type MemoReturn = 'return'; - class Memo { - static fromXDRObject(memo: xdr.Memo): Memo; - static hash(hash: string): Memo; - static id(id: string): Memo; - static none(): Memo; - static return(hash: string): Memo; - static text(text: string): Memo; - - constructor(type: MemoNone, value?: null); - constructor(type: MemoHash | MemoReturn, value: Buffer) - constructor(type: MemoHash | MemoReturn | MemoID | MemoText, value: string) - constructor(type: T, value: Memo.AnyValue) - - type: T; - value: - T extends MemoNone ? null : - T extends MemoID ? string : - T extends MemoText ? string : - T extends MemoHash ? Buffer : - T extends MemoReturn ? Buffer : - Memo.AnyValue; - - toXDRObject(): xdr.Memo; - } - namespace Memo { - type AnyType = MemoNone | MemoID | MemoText | MemoHash | MemoReturn; - type AnyValue = null | string | Buffer; - } - - enum Networks { - PUBLIC = 'Public Global Stellar Network ; September 2015', - TESTNET = 'Test SDF Network ; September 2015', - } - - class Network { - static use(network: Network): void; - static usePublicNetwork(): void; - static useTestNetwork(): void; - static current(): Network; - - constructor(passphrase: string) - - networkPassphrase(): string; - networkId(): string; - } - - const AuthRequiredFlag: 1; - const AuthRevocableFlag: 2; - const AuthImmutableFlag: 4; - - type TransactionOperation = - Operation.CreateAccount - | Operation.Payment - | Operation.PathPayment - | Operation.CreatePassiveOffer - | Operation.ManageOffer - | Operation.SetOptions - | Operation.ChangeTrust - | Operation.AllowTrust - | Operation.AccountMerge - | Operation.Inflation - | Operation.ManageData - | Operation.BumpSequence; - - enum OperationType { - createAccount = 'createAccount', - payment = 'payment', - pathPayment = 'pathPayment', - createPassiveOffer = 'createPassiveOffer', - manageOffer = 'manageOffer', - setOptions = 'setOptions', - changeTrust = 'changeTrust', - allowTrust = 'allowTrust', - accountMerge = 'accountMerge', - inflation = 'inflation', - manageData = 'manageData', - bumpSequence = 'bumpSequence', - } - - namespace Operation { - interface Operation { - type: T; - source?: string; - } - interface OperationOptions { - source?: string; - } - - interface AccountMerge extends Operation { - destination: string; - } - interface AccountMergeOptions extends OperationOptions { - destination: string; - } - function accountMerge(options: AccountMergeOptions): xdr.Operation; - - interface AllowTrust extends Operation { - trustor: string; - assetCode: string; - authorize: boolean | undefined; - } - interface AllowTrustOptions extends OperationOptions { - trustor: string; - assetCode: string; - authorize?: boolean; - } - function allowTrust(options: AllowTrustOptions): xdr.Operation; - - interface ChangeTrust extends Operation { - line: Asset; - limit: string; - } - interface ChangeTrustOptions extends OperationOptions { - asset: Asset; - limit?: string; - } - function changeTrust(options: ChangeTrustOptions): xdr.Operation; - - interface CreateAccount extends Operation { - destination: string; - startingBalance: string; - } - interface CreateAccountOptions extends OperationOptions { - destination: string; - startingBalance: string; - } - function createAccount(options: CreateAccountOptions): xdr.Operation; - - interface CreatePassiveOffer extends Operation { - selling: Asset; - buying: Asset; - amount: string; - price: string; - } - interface CreatePassiveOfferOptions extends OperationOptions { - selling: Asset; - buying: Asset; - amount: string; - price: number | string | object /* bignumber.js */; - } - function createPassiveOffer(options: CreatePassiveOfferOptions): xdr.Operation; - - interface Inflation extends Operation { - } - interface InflationOptions extends OperationOptions { // tslint:disable-line - } - function inflation(options: InflationOptions): xdr.Operation; - - interface ManageData extends Operation { - name: string; - value: Buffer; - } - interface ManageDataOptions extends OperationOptions { - name: string; - value: string | Buffer; - } - function manageData(options: ManageDataOptions): xdr.Operation; - - interface ManageOffer extends Operation { - selling: Asset; - buying: Asset; - amount: string; - price: string; - offerId: string; - } - interface ManageOfferOptions extends CreatePassiveOfferOptions { - offerId?: number | string; - } - function manageOffer(options: ManageOfferOptions): xdr.Operation; - - interface PathPayment extends Operation { - sendAsset: Asset; - sendMax: string; - destination: string; - destAsset: Asset; - destAmount: string; - path: Asset[]; - } - interface PathPaymentOptions extends OperationOptions { - sendAsset: Asset; - sendMax: string; - destination: string; - destAsset: Asset; - destAmount: string; - path?: Asset[]; - } - function pathPayment(options: PathPaymentOptions): xdr.Operation; - - interface Payment extends Operation { - amount: string; - asset: Asset; - destination: string; - } - interface PaymentOptions extends OperationOptions { - amount: string; - asset: Asset; - destination: string; - } - function payment(options: PaymentOptions): xdr.Operation; - - /* - * Required = 1 << 0 - * Revocable = 1 << 1 - * Immutable = 1 << 2 - */ - enum AuthFlags { - Required = 1, - Revocable = 2, - Immutable = 4, - } - interface SignerEd25519PublicKey { - ed25519PublicKey: string; - weight: number | undefined; - } - interface SignerSha256Hash { - sha256Hash: Buffer; - weight: number | undefined; - } - interface SignerPreAuthTx { - preAuthTx: Buffer; - weight: number | undefined; - } - type Signer = SignerEd25519PublicKey | SignerSha256Hash | SignerPreAuthTx; - interface SignerEd25519PublicKeyOptions { - ed25519PublicKey: string; - weight?: number | string; - } - interface SignerSha256HashOptions { - sha256Hash: Buffer | string; - weight?: number | string; - } - interface SignerPreAuthTxOptions { - preAuthTx: Buffer | string; - weight?: number | string; - } - type SignerOptions = SignerEd25519PublicKeyOptions | SignerSha256HashOptions | SignerPreAuthTxOptions; - type SignerUnion = {ed25519PublicKey: any} | {sha256Hash: any} | {preAuthTx: any} | null; - interface SetOptions extends Operation { - inflationDest?: string; - clearFlags?: AuthFlags; - setFlags?: AuthFlags; - masterWeight?: number; - lowThreshold?: number; - medThreshold?: number; - highThreshold?: number; - homeDomain?: string; - signer: - T extends {ed25519PublicKey: any} ? SignerEd25519PublicKey : - T extends {sha256Hash: any} ? SignerSha256Hash : - T extends {preAuthTx: any} ? SignerPreAuthTx : - never; - } - interface SetOptionsOptions extends OperationOptions { - inflationDest?: string; - clearFlags?: AuthFlags; - setFlags?: AuthFlags; - masterWeight?: number | string; - lowThreshold?: number | string; - medThreshold?: number | string; - highThreshold?: number | string; - homeDomain?: string; - signer?: T; - } - function setOptions(options: SetOptionsOptions): xdr.Operation>; - - interface BumpSequence extends Operation { - bumpTo: string; - } - interface BumpSequenceOptions extends OperationOptions { - bumpTo: string; - } - function bumpSequence(options: BumpSequenceOptions): xdr.Operation; - - function fromXDRObject(xdrOperation: xdr.Operation): T; - } - - namespace StrKey { - function encodeEd25519PublicKey(data: Buffer): string; - function decodeEd25519PublicKey(data: string): Buffer; - function isValidEd25519PublicKey(Key: string): boolean; - - function encodeEd25519SecretSeed(data: Buffer): string; - function decodeEd25519SecretSeed(data: string): Buffer; - function isValidEd25519SecretSeed(seed: string): boolean; - - function encodePreAuthTx(data: Buffer): string; - function decodePreAuthTx(data: string): Buffer; - - function encodeSha256Hash(data: Buffer): string; - function decodeSha256Hash(data: string): Buffer; - } - - class Transaction { - constructor(envelope: string | xdr.TransactionEnvelope) - hash(): Buffer; - sign(...keypairs: Keypair[]): void; - signatureBase(): Buffer; - signHashX(preimage: Buffer | string): void; - toEnvelope(): xdr.TransactionEnvelope; - - operations: TransactionOperation[]; - sequence: number; - fee: number; - source: string; - memo: Memo; - signatures: xdr.DecoratedSignature[]; - } - - class TransactionBuilder { - constructor(sourceAccount: Account, options?: TransactionBuilder.TransactionBuilderOptions) - addOperation(operation: xdr.Operation): this; - addMemo(memo: Memo): this; - build(): Transaction; - } - - namespace TransactionBuilder { - interface TransactionBuilderOptions { - fee?: number; - timebounds?: { - minTime?: number | string - maxTime?: number | string - }; - memo?: Memo; - } - } - - namespace xdr { - class XDRStruct { - static fromXDR(xdr: Buffer): XDRStruct; - - toXDR(base?: string): Buffer; - toXDR(encoding: string): string; - } - class Operation extends XDRStruct { - static fromXDR(xdr: Buffer): Operation; - } - class Asset extends XDRStruct { - static fromXDR(xdr: Buffer): Asset; - } - class Memo extends XDRStruct { - static fromXDR(xdr: Buffer): Memo; - } - class TransactionEnvelope extends XDRStruct { - static fromXDR(xdr: Buffer): TransactionEnvelope; - } - class DecoratedSignature extends XDRStruct { - static fromXDR(xdr: Buffer): DecoratedSignature; - - constructor(keys: { hint: SignatureHint, signature: Signature }) - - hint(): SignatureHint; - signature(): Buffer; - } - type SignatureHint = Buffer; - type Signature = Buffer; - - class TransactionResult extends XDRStruct { - static fromXDR(xdr: Buffer): TransactionResult; - } - } - - function hash(data: Buffer): Buffer; - function sign(data: Buffer, rawSecret: Buffer): Buffer; - function verify(data: Buffer, signature: Buffer, rawPublicKey: Buffer): boolean; -} +import { AssetType, Asset, Memo, MemoType, Transaction } from 'stellar-base'; // Re-StellarBase -export import Account = StellarBase.Account; -export import ASSET_TYPE = StellarBase.ASSET_TYPE; -export import Asset = StellarBase.Asset; -export import FastSigning = StellarBase.FastSigning; -export import Keypair = StellarBase.Keypair; -export import Memo = StellarBase.Memo; -export import MemoHash = StellarBase.MemoHash; -export import MemoID = StellarBase.MemoID; -export import MemoNone = StellarBase.MemoNone; -export import MemoReturn = StellarBase.MemoReturn; -export import MemoText = StellarBase.MemoText; -export import Network = StellarBase.Network; -export import Networks = StellarBase.Networks; -export import Operation = StellarBase.Operation; -export import OperationType = StellarBase.OperationType; -export import StrKey = StellarBase.StrKey; -export import Transaction = StellarBase.Transaction; -export import TransactionBuilder = StellarBase.TransactionBuilder; -export import TransactionOperation = StellarBase.TransactionOperation; -export import hash = StellarBase.hash; -export import sign = StellarBase.sign; -export import verify = StellarBase.verify; -export import xdr = StellarBase.xdr; +export { + Account, + Asset, + AssetType, + AuthFlag, + AuthImmutableFlag, + AuthRequiredFlag, + AuthRevocableFlag, + FastSigning, + Keypair, + Memo, + MemoType, + MemoValue, + MemoHash, + MemoID, + MemoNone, + MemoReturn, + MemoText, + Network, + Networks, + Operation, + OperationOptions, + OperationType, + StrKey, + Signer, + SignerOptions, + Transaction, + TransactionBuilder, + hash, + sign, + verify, + xdr +} from 'stellar-base'; + +// Shorthands, not-to-export. +export {}; +type Key = string|number|symbol; +type Diff = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]; +type Omit = Pick>; export class NetworkError extends Error { private response: any; @@ -512,7 +101,7 @@ export class Server { } export namespace Server { - abstract class CallBuilder { + abstract class CallBuilder { constructor(serverUrl: string) call(): Promise>; cursor(cursor: string): this; @@ -521,29 +110,18 @@ export namespace Server { stream(options?: { onmessage?: (record: T) => void, onerror?: (error: Error) => void }): () => void; } - interface CollectionPage { + interface CollectionPage { records: T[]; next: () => Promise>; prev: () => Promise>; } - interface Record { - _links: { - [key: string]: RecordLink - }; - } - - interface RecordLink { - href: string; - templated?: boolean; - } - /* Due to a bug with the recursive function requests */ - interface CollectionRecord { + interface CollectionRecord { _links: { - next: RecordLink - prev: RecordLink - self: RecordLink + next: Horizon.ResponseLink + prev: Horizon.ResponseLink + self: Horizon.ResponseLink }; _embedded: { records: T[] @@ -556,42 +134,19 @@ export namespace Server { order?: 'asc' | 'desc'; } - type CallFunction = () => Promise; - type CallCollectionFunction = + type CallFunction = () => Promise; + type CallCollectionFunction = (options?: CallFunctionTemplateOptions) => Promise>; - interface BalanceLineNative { - balance: string; - asset_type: ASSET_TYPE.native; - } - interface BalanceLineAsset { - balance: string; - limit: string; - asset_type: T; - asset_code: string; - asset_issuer: string; - } - type BalanceLine = - T extends ASSET_TYPE.native ? BalanceLineNative : - T extends ASSET_TYPE.credit4 | ASSET_TYPE.credit12 ? BalanceLineAsset : - BalanceLineNative | BalanceLineAsset; - - interface AccountRecord extends Record { + interface AccountRecord extends Horizon.BaseResponse { id: string; paging_token: string; account_id: string; sequence: number; subentry_count: number; - thresholds: { - low_threshold: number - med_threshold: number - high_threshold: number - }; - flags: { - auth_required: boolean - auth_revocable: boolean - }; - balances: BalanceLine[]; + thresholds: Horizon.AccountThresholds; + flags: Horizon.Flags; + balances: Horizon.BalanceLine[]; signers: Array< { public_key: string @@ -609,20 +164,17 @@ export namespace Server { trades: CallCollectionFunction; } - interface AssetRecord extends Record { - asset_type: ASSET_TYPE.credit4 | ASSET_TYPE.credit12; + interface AssetRecord extends Horizon.BaseResponse { + asset_type: AssetType.credit4 | AssetType.credit12; asset_code: string; asset_issuer: string; paging_token: string; amount: string; num_accounts: number; - flags: { - auth_required: boolean - auth_revocable: boolean - }; + flags: Horizon.Flags; } - interface EffectRecord extends Record { + interface EffectRecord extends Horizon.BaseResponse { account: string; paging_token: string; starting_balance: string; @@ -635,7 +187,7 @@ export namespace Server { succeeds?: CallFunction; } - interface LedgerRecord extends Record { + interface LedgerRecord extends Horizon.BaseResponse { id: string; paging_token: string; hash: string; @@ -660,150 +212,47 @@ export namespace Server { transactions: CallCollectionFunction; } - interface OfferRecord extends Record { + interface OfferRecord extends Horizon.BaseResponse { id: string; paging_token: string; seller_attr: string; selling: Asset; buying: Asset; amount: string; - price_r: { numerator: number, denominator: number }; + price_r: Horizon.PriceR; price: string; seller?: CallFunction; } - interface BaseOperationRecord extends Record { - id: string; - paging_token: string; - type: string; - type_i: number; - source_account: string; - - self: CallFunction; - succeeds: CallFunction; - precedes: CallFunction; - effects: CallCollectionFunction; - transaction: CallFunction; + import OperationResponseType = Horizon.OperationResponseType; + import OperationResponseTypeI = Horizon.OperationResponseTypeI; + interface BaseOperationRecord< + T extends OperationResponseType = OperationResponseType, + TI extends OperationResponseTypeI = OperationResponseTypeI, + > extends Horizon.BaseOperationResponse { + self: CallFunction; + succeeds: CallFunction; + precedes: CallFunction; + effects: CallCollectionFunction; + transaction: CallFunction; } - interface CreateAccountOperationRecord extends BaseOperationRecord { - type: 'create_account'; - account: string; - funder: string; - starting_balance: string; - } - - interface PaymentOperationRecord extends BaseOperationRecord { - type: 'payment'; - from: string; - to: string; - asset_type: string; - asset_code?: string; - asset_issuer?: string; - amount: string; - + interface CreateAccountOperationRecord extends BaseOperationRecord, Horizon.CreateAccountOperationResponse {} + interface PaymentOperationRecord extends BaseOperationRecord, Horizon.PaymentOperationResponse { sender: CallFunction; receiver: CallFunction; } - - interface PathPaymentOperationRecord extends BaseOperationRecord { - type: 'path_payment'; - from: string; - to: string; - asset_code?: string; - asset_issuer?: string; - asset_type: string; - amount: string; - source_asset_code?: string; - source_asset_issuer?: string; - source_asset_type: string; - source_max: string; - source_amount: string; - } - - interface ManageOfferOperationRecord extends BaseOperationRecord { - type: 'manage_offer'; - offer_id: number; - amount: string; - buying_asset_code?: string; - buying_asset_issuer?: string; - buying_asset_type: string; - price: string; - price_r: { numerator: number, denominator: number }; - selling_asset_code?: string; - selling_asset_issuer?: string; - selling_asset_type: string; - } - - interface PassiveOfferOperationRecord extends BaseOperationRecord { - type: 'create_passive_offer'; - offer_id: number; - amount: string; - buying_asset_code?: string; - buying_asset_issuer?: string; - buying_asset_type: string; - price: string; - price_r: { numerator: number, denominator: number }; - selling_asset_code?: string; - selling_asset_issuer?: string; - selling_asset_type: string; - } - - interface SetOptionsOperationRecord extends BaseOperationRecord { - type: 'set_options'; - signer_key?: string; - signer_weight?: number; - master_key_weight?: number; - low_threshold?: number; - med_threshold?: number; - high_threshold?: number; - home_domain?: string; - set_flags: Array<(1 | 2)>; - set_flags_s: Array<('auth_required_flag' | 'auth_revocable_flag')>; - clear_flags: Array<(1 | 2)>; - clear_flags_s: Array<('auth_required_flag' | 'auth_revocable_flag')>; - } - - interface ChangeTrustOperationRecord extends BaseOperationRecord { - type: 'change_trust'; - asset_code: string; - asset_issuer: string; - asset_type: string; - trustee: string; - trustor: string; - limit: string; - } - - interface AllowTrustOperationRecord extends BaseOperationRecord { - type: 'allow_trust'; - asset_code: string; - asset_issuer: string; - asset_type: string; - authorize: boolean; - trustee: string; - trustor: string; - } - - interface AccountMergeOperationRecord extends BaseOperationRecord { - type: 'account_merge'; - into: string; - } - - interface InflationOperationRecord extends BaseOperationRecord { - type: 'inflation'; - } - - interface ManageDataOperationRecord extends BaseOperationRecord { - type: 'manage_data'; - name: string; - value: Buffer; - } - - interface BumpSequenceOperationRecord extends BaseOperationRecord { - type: 'bump_sequence'; - bump_to: string; - } + interface PathPaymentOperationRecord extends BaseOperationRecord, Horizon.PathPaymentOperationResponse {} + interface ManageOfferOperationRecord extends BaseOperationRecord, Horizon.ManageOfferOperationResponse {} + interface PassiveOfferOperationRecord extends BaseOperationRecord, Horizon.PassiveOfferOperationResponse {} + interface SetOptionsOperationRecord extends BaseOperationRecord, Horizon.SetOptionsOperationResponse {} + interface ChangeTrustOperationRecord extends BaseOperationRecord, Horizon.ChangeTrustOperationResponse {} + interface AllowTrustOperationRecord extends BaseOperationRecord, Horizon.AllowTrustOperationResponse {} + interface AccountMergeOperationRecord extends BaseOperationRecord, Horizon.AccountMergeOperationResponse {} + interface InflationOperationRecord extends BaseOperationRecord, Horizon.InflationOperationResponse {} + interface ManageDataOperationRecord extends BaseOperationRecord, Horizon.ManageDataOperationResponse {} + interface BumpSequenceOperationRecord extends BaseOperationRecord, Horizon.BumpSequenceOperationResponse {} type OperationRecord = CreateAccountOperationRecord | PaymentOperationRecord @@ -818,14 +267,14 @@ export namespace Server { | ManageDataOperationRecord | BumpSequenceOperationRecord; - interface OrderbookRecord extends Record { + interface OrderbookRecord extends Horizon.BaseResponse { bids: Array<{ price_r: {}, price: number, amount: string }>; asks: Array<{ price_r: {}, price: number, amount: string }>; selling: Asset; buying: Asset; } - interface PaymentPathRecord extends Record { + interface PaymentPathRecord extends Horizon.BaseResponse { path: Array<{ asset_code: string asset_issuer: string @@ -841,7 +290,7 @@ export namespace Server { destination_asset_issuer: string; } - interface TradeRecord extends Record { + interface TradeRecord extends Horizon.BaseResponse { id: string; paging_token: string; ledger_close_time: string; @@ -862,7 +311,7 @@ export namespace Server { operation: CallFunction; } - interface TradeAggregationRecord extends Record { + interface TradeAggregationRecord extends Horizon.BaseResponse { timestamp: string; trade_count: number; base_volume: string; @@ -874,25 +323,8 @@ export namespace Server { close: string; } - interface TransactionRecord extends Record { - id: string; - paging_token: string; - hash: string; - ledger_attr: number; - created_at: string; - max_fee: number; - fee_paid: number; - operation_count: number; - result_code: number; - result_code_s: string; - source_account: string; - source_account_sequence: string; - envelope_xdr: string; - result_xdr: string; - result_meta_xdr: string; - memo: string; - envelope: any; - memo_type: any; + interface TransactionRecord extends Omit { + ledger_attr: Horizon.TransactionResponse['ledger']; account: CallFunction; effects: CallCollectionFunction; @@ -907,28 +339,16 @@ export namespace Server { accountId(id: string): this; } class AccountResponse implements AccountRecord { - _links: { [key: string]: { href: string } }; + _links: { [key in 'self']: Horizon.ResponseLink }; id: string; paging_token: string; account_id: string; sequence: number; subentry_count: number; - thresholds: { - low_threshold: number - med_threshold: number - high_threshold: number - }; - flags: { - auth_required: boolean - auth_revocable: boolean - }; - balances: BalanceLine[]; - signers: Array< - { - public_key: string - weight: number - } - >; + thresholds: Horizon.AccountThresholds; + flags: Horizon.Flags; + balances: Horizon.BalanceLine[]; + signers: Horizon.AccountSigner[]; data: (options: {value: string}) => Promise<{value: string}>; data_attr: { [key: string]: string @@ -1021,3 +441,225 @@ export namespace StellarTomlResolver { function resolve(domain: string, options?: StellarTomlResolveOptions): Promise<{ [key: string]: any }>; } + +export namespace Horizon { + interface ResponseLink { + href: string; + templated?: boolean; + } + interface BaseResponse { + _links: { + [key in T|'self']: ResponseLink + }; + } + interface TransactionResponse extends BaseResponse<'account'|'ledger'|'operations'|'effects'|'succeeds'|'precedes'> { + created_at: string; + envelope_xdr: string; + fee_meta_xdr: string; + fee_paid: number; + hash: string; + id: string; + ledger: number; + memo_type: MemoType; + memo?: string; + operation_count: number; + paging_token: string; + result_meta_xdr: string; + result_xdr: string; + signatures: string[]; + source_account: string; + source_account_sequence: string; + } + + interface BalanceLineNative { + balance: string; + asset_type: AssetType.native; + } + interface BalanceLineAsset { + balance: string; + limit: string; + asset_type: T; + asset_code: string; + asset_issuer: string; + } + type BalanceLine = + T extends AssetType.native ? BalanceLineNative : + T extends AssetType.credit4 | AssetType.credit12 ? BalanceLineAsset : + BalanceLineNative | BalanceLineAsset; + + interface PriceR { + numerator: number; + denominator: number; + } + interface AccountThresholds { + low_threshold: number; + med_threshold: number; + high_threshold: number; + } + interface Flags { + auth_required: boolean; + auth_revocable: boolean; + } + interface AccountSigner { + public_key: string; + weight: number; + } + interface AccountResponse extends BaseResponse<'transactions'|'operations'|'payments'|'effects'|'offers'|'trades'|'data'> { + id: string; + paging_token: string; + account_id: string; + sequence: string; + subentry_count: number; + thresholds: AccountThresholds; + flags: Flags; + balances: BalanceLine[]; + signers: AccountSigner[]; + data: { + [key: string]: string + }; + } + + enum OperationResponseType { + createAccount = 'create_account', + payment = 'payment', + pathPayment = 'path_payment', + createPassiveOffer = 'create_passive_offer', + manageOffer = 'manage_offer', + setOptions = 'set_options', + changeTrust = 'change_trust', + allowTrust = 'allow_trust', + accountMerge = 'account_merge', + inflation = 'inflation', + manageData = 'manage_data', + bumpSequence = 'bump_sequence', + } + enum OperationResponseTypeI { + createAccount = 0, + payment = 1, + pathPayment = 2, + createPassiveOffer = 3, + manageOffer = 4, + setOptions = 5, + changeTrust = 6, + allowTrust = 7, + accountMerge = 8, + inflation = 9, + manageData = 10, + bumpSequence = 11, + } + interface BaseOperationResponse< + T extends OperationResponseType = OperationResponseType, + TI extends OperationResponseTypeI = OperationResponseTypeI, + > extends BaseResponse<'succeeds'|'precedes'|'effects'|'transaction'> { + id: string; + paging_token: string; + source_account: string; + type: T; + type_i: TI; + created_at: string; + transaction_hash: string; + } + interface CreateAccountOperationResponse extends BaseOperationResponse { + account: string; + funder: string; + starting_balance: string; + } + interface PaymentOperationResponse extends BaseOperationResponse { + from: string; + to: string; + asset_type: AssetType; + asset_code?: string; + asset_issuer?: string; + amount: string; + } + interface PathPaymentOperationResponse extends BaseOperationResponse { + from: string; + to: string; + asset_type: AssetType; + asset_code?: string; + asset_issuer?: string; + amount: string; + source_asset_type: AssetType; + source_asset_code?: string; + source_asset_issuer?: string; + source_max: string; + source_amount: string; + } + interface ManageOfferOperationResponse extends BaseOperationResponse { + offer_id: number; + amount: string; + buying_asset_type: AssetType; + buying_asset_code?: string; + buying_asset_issuer?: string; + price: string; + price_r: PriceR; + selling_asset_type: AssetType; + selling_asset_code?: string; + selling_asset_issuer?: string; + } + interface PassiveOfferOperationResponse extends BaseOperationResponse { + offer_id: number; + amount: string; + buying_asset_type: AssetType; + buying_asset_code?: string; + buying_asset_issuer?: string; + price: string; + price_r: PriceR; + selling_asset_type: AssetType; + selling_asset_code?: string; + selling_asset_issuer?: string; + } + interface SetOptionsOperationResponse extends BaseOperationResponse { + signer_key?: string; + signer_weight?: number; + master_key_weight?: number; + low_threshold?: number; + med_threshold?: number; + high_threshold?: number; + home_domain?: string; + set_flags: Array<(1 | 2)>; + set_flags_s: Array<('auth_required_flag' | 'auth_revocable_flag')>; + clear_flags: Array<(1 | 2)>; + clear_flags_s: Array<('auth_required_flag' | 'auth_revocable_flag')>; + } + interface ChangeTrustOperationResponse extends BaseOperationResponse { + asset_type: AssetType.credit4 | AssetType.credit12; + asset_code: string; + asset_issuer: string; + trustee: string; + trustor: string; + limit: string; + } + interface AllowTrustOperationResponse extends BaseOperationResponse { + asset_type: AssetType; + asset_code: string; + asset_issuer: string; + authorize: boolean; + trustee: string; + trustor: string; + } + interface AccountMergeOperationResponse extends BaseOperationResponse { + into: string; + } + interface InflationOperationResponse extends BaseOperationResponse { + } + interface ManageDataOperationResponse extends BaseOperationResponse { + name: string; + value: Buffer; + } + interface BumpSequenceOperationResponse extends BaseOperationResponse { + bump_to: string; + } + + interface ResponseCollection { + _links: { + self: ResponseLink + next: ResponseLink + prev: ResponseLink + }; + _embedded: { + records: T[] + }; + } + interface TransactionResponseCollection extends ResponseCollection {} +} diff --git a/types/stellar-sdk/stellar-sdk-tests.ts b/types/stellar-sdk/stellar-sdk-tests.ts index c4dcbda7c8..d531fc850f 100644 --- a/types/stellar-sdk/stellar-sdk-tests.ts +++ b/types/stellar-sdk/stellar-sdk-tests.ts @@ -1,44 +1,4 @@ import * as StellarSdk from 'stellar-sdk'; -const sourceKey = StellarSdk.Keypair.random(); // $ExpectType Keypair -const destKey = StellarSdk.Keypair.random(); -const account = new StellarSdk.Account(sourceKey.publicKey(), '1'); -const transaction = new StellarSdk.TransactionBuilder(account) - .addOperation(StellarSdk.Operation.accountMerge({destination: destKey.publicKey()})) - .addMemo(new StellarSdk.Memo(StellarSdk.MemoText, "memo")) - .build(); // $ExpectType () => Transaction -transaction; // $ExpectType Transaction - StellarSdk.StellarTomlResolver.resolve("example.com", {allowHttp: true, timeout: 100}) .then(toml => toml.FEDERATION_SERVER); - -const sig = StellarSdk.xdr.DecoratedSignature.fromXDR(Buffer.of(1, 2)); // $ExpectType DecoratedSignature -sig.hint(); // $ExpectType Buffer -sig.signature(); // $ExpectType Buffer - -StellarSdk.Memo.none(); // $ExpectType Memo<"none"> -StellarSdk.Memo.text('asdf'); // $ExpectType Memo<"text"> -StellarSdk.Memo.id('asdf'); // $ExpectType Memo<"id"> -StellarSdk.Memo.return('asdf'); // $ExpectType Memo<"return"> -StellarSdk.Memo.hash('asdf'); // $ExpectType Memo<"hash"> -StellarSdk.Memo.none().value; // $ExpectType null -StellarSdk.Memo.id('asdf').value; // $ExpectType string -StellarSdk.Memo.text('asdf').value; // $ExpectType string -StellarSdk.Memo.return('asdf').value; // $ExpectType Buffer -StellarSdk.Memo.hash('asdf').value; // $ExpectType Buffer - -// P.S. don't use Memo constructor -(new StellarSdk.Memo(StellarSdk.MemoHash, 'asdf')).value; // $ExpectType AnyValue -(new StellarSdk.Memo(StellarSdk.MemoHash, 'asdf')).type; // $ExpectType AnyType - -const noSignerXDR = StellarSdk.Operation.setOptions({lowThreshold: 1}); -StellarSdk.Operation.fromXDRObject(noSignerXDR).signer; // $ExpectType never - -const newSignerXDR1 = StellarSdk.Operation.setOptions({signer: {ed25519PublicKey: sourceKey.publicKey(), weight: '1'}}); -StellarSdk.Operation.fromXDRObject(newSignerXDR1).signer; // $ExpectType SignerEd25519PublicKey - -const newSignerXDR2 = StellarSdk.Operation.setOptions({signer: {sha256Hash: Buffer.from(''), weight: '1'}}); -StellarSdk.Operation.fromXDRObject(newSignerXDR2).signer; // $ExpectType SignerSha256Hash - -const newSignerXDR3 = StellarSdk.Operation.setOptions({signer: {preAuthTx: '', weight: 1}}); -StellarSdk.Operation.fromXDRObject(newSignerXDR3).signer; // $ExpectType SignerPreAuthTx