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

fix: (SEP-10) value of the first op should not be null. #591

Merged
merged 1 commit into from
Jan 17, 2021
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
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ export namespace Utils {
throw new InvalidSep10ChallengeError("The transaction has expired");
}

if (operation.value === undefined) {
overcat marked this conversation as resolved.
Show resolved Hide resolved
throw new InvalidSep10ChallengeError(
"The transaction's operation value should not be null",
);
}

// verify base64
if (Buffer.from(operation.value.toString(), "base64").length !== 48) {
throw new InvalidSep10ChallengeError(
Expand Down
35 changes: 35 additions & 0 deletions test/unit/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,41 @@ describe('Utils', function() {
);
});

it("throws an error if operation value is null", function() {
let keypair = StellarSdk.Keypair.random();
const account = new StellarSdk.Account(keypair.publicKey(), "-1");
const transaction = new StellarSdk.TransactionBuilder(
account,
txBuilderOpts,
)
.addOperation(
StellarSdk.Operation.manageData({
name: "SDF auth",
value: null,
overcat marked this conversation as resolved.
Show resolved Hide resolved
source: "GBDIT5GUJ7R5BXO3GJHFXJ6AZ5UQK6MNOIDMPQUSMXLIHTUNR2Q5CFNF",
}),
)
.setTimeout(30)
.build();

transaction.sign(keypair);
const challenge = transaction
.toEnvelope()
.toXDR("base64")
.toString();

expect(() =>
StellarSdk.Utils.readChallengeTx(
challenge,
keypair.publicKey(),
StellarSdk.Networks.TESTNET,
),
).to.throw(
StellarSdk.InvalidSep10ChallengeError,
/The transaction\'s operation value should not be null/,
);
});

it("throws an error if transaction does not contain valid timeBounds", function() {
let keypair = StellarSdk.Keypair.random();
let clientKeypair = StellarSdk.Keypair.random();
Expand Down