Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types for new networkPassphrase argument. Fix #237. #238

Merged
merged 1 commit into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Keypair {
static fromRawEd25519Seed(secretSeed: Buffer): Keypair;
static fromBase58Seed(secretSeed: string): Keypair;
static fromSecret(secretKey: string): Keypair;
static master(): Keypair;
static master(networkPassphrase?: string): Keypair;
static fromPublicKey(publicKey: string): Keypair;
static random(): Keypair;

Expand Down Expand Up @@ -478,7 +478,7 @@ export class Transaction<
TMemo extends Memo = Memo,
TOps extends Operation[] = Operation[]
> {
constructor(envelope: string | xdr.TransactionEnvelope);
constructor(envelope: string | xdr.TransactionEnvelope, networkPassphrase?: string);
addSignature(publicKey: string, signature: string): void;
getKeypairSignature(keypair: Keypair): string;
hash(): Buffer;
Expand All @@ -492,6 +492,7 @@ export class Transaction<
fee: number;
source: string;
memo: TMemo;
networkPassphrase: string;
signatures: xdr.DecoratedSignature[];
timeBounds?: {
minTime: string;
Expand All @@ -511,6 +512,7 @@ export class TransactionBuilder {
addMemo(memo: Memo): this;
setTimeout(timeoutInSeconds: number): this;
build(): Transaction;
setNetworkPassphrase(networkPassphrase: string): this;
}

export namespace TransactionBuilder {
Expand All @@ -521,6 +523,7 @@ export namespace TransactionBuilder {
maxTime?: number | string;
};
memo?: Memo;
networkPassphrase?: string;
}
}

Expand Down
11 changes: 10 additions & 1 deletion types/test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import * as StellarSdk from 'stellar-base';

const masterKey = StellarSdk.Keypair.master(StellarSdk.Networks.TESTNET); // $ExpectType Keypair
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)
const transaction = new StellarSdk.TransactionBuilder(account, {
fee: 100,
networkPassphrase: StellarSdk.Networks.TESTNET
})
.addOperation(
StellarSdk.Operation.accountMerge({ destination: destKey.publicKey() })
)
.addMemo(new StellarSdk.Memo(StellarSdk.MemoText, 'memo'))
.setTimeout(5)
.build(); // $ExpectType () => Transaction<Memo<MemoType>, Operation[]>

const transactionFromXDR = new StellarSdk.Transaction(transaction.toEnvelope(), StellarSdk.Networks.TESTNET); // $ExpectType Transaction<Memo<MemoType>, Operation[]>

transactionFromXDR.networkPassphrase; // $ExpectType string
transactionFromXDR.networkPassphrase = "SDF";

const sig = StellarSdk.xdr.DecoratedSignature.fromXDR(Buffer.of(1, 2)); // $ExpectType DecoratedSignature
sig.hint(); // $ExpectType Buffer
sig.signature(); // $ExpectType Buffer
Expand Down