Skip to content

Commit

Permalink
Add types for new networkPassphrase argument. Fix #237.
Browse files Browse the repository at this point in the history
  • Loading branch information
abuiles committed Aug 5, 2019
1 parent d440d39 commit 881f67c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 6 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,14 +478,16 @@ 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;
sign(...keypairs: Keypair[]): void;
signatureBase(): Buffer;
signHashX(preimage: Buffer | string): void;
toEnvelope(): xdr.TransactionEnvelope;
get networkPassphrase: string;
set networkPassphrase;

operations: TOps;
sequence: string;
Expand All @@ -511,6 +513,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 +524,7 @@ export namespace TransactionBuilder {
maxTime?: number | string;
};
memo?: Memo;
networkPassphrase?: string;
}
}

Expand Down
14 changes: 13 additions & 1 deletion types/test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
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

0 comments on commit 881f67c

Please sign in to comment.