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

Removed SignedData and Updated SignedMessage #96

Closed
Closed
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
9 changes: 1 addition & 8 deletions docs/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,13 @@ Account.isValidPair("SIGNING_KEY", "ACCOUNT_NUMBER"); // returns true only if th

## Using Signed Data and Signed Messages

We have already talked about creating signatures, so let's learn how we can apply them to creating signed data and signed messages. Signed data and signed messages are very similar, with the only difference being that signed messages have an extra `node_identifier` property. Here is an example of us creating signed data and a signed message:
We have already talked about creating signatures, so let's learn how we can apply them to creating signed messages. Here is an example of us creating a signed message:

> Note that all of the `signature` and `node_identifier` properties that we are generating are _almost_ random as we are not passing any arguments into the `Account` class.

```ts
const account = new Account();

account.createSignedData({ name: "Bacon" });

// {
// data: { name: 'Bacon' },
// signature: '68202fd5336c57dd42ba116fbf4154b7ef797473c7bc04949fef943c37b7b448ababf22c94711cd5f0fc603f5bd7d10d4e96dff9c876599de9fe887dfffe6d01'
// }

account.createSignedMessage({ name: "Tuna" });

// {
Expand Down
19 changes: 3 additions & 16 deletions src/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAccountData, uint8arrayToHex, hexToUint8Array } from "./utils";
import type { BlockData, BlockMessage, SignedData, SignedMessage, Transaction } from "./models";
import type { BlockData, BlockMessage, SignedMessage, Transaction } from "./models";
import { sign } from "tweetnacl";

type AccountKeys = [Uint8Array, Uint8Array];
Expand Down Expand Up @@ -77,29 +77,16 @@ export class Account {
return signature.substring(0, 128);
}

/**
* Creates a signed data object.
* @param data the data to be used to generate the signature
* @returns the signed data object
*/
createSignedData<T>(data: T): SignedData<T> {
return {
data,
signature: this.createSignature(JSON.stringify(data)),
};
}

/**
* Creates a signed data message with the given data.
* @param data the data to be passed along in the message
* @returns the signed message
*/
createSignedMessage<T>(data: T): SignedMessage<T> {
const { data: _data, signature } = this.createSignedData(data);
return {
data: _data,
message: data,
node_identifier: this.accountNumberHex,
signature,
signature: this.createSignature(JSON.stringify(data)),
};
}

Expand Down
1 change: 0 additions & 1 deletion src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export type { ServerNodeOptions } from "./server-node-options";
export type { PaymentHandlerOptions } from "./payment-handler-options";
export type { AccountPaymentHandlerOptions } from "./account-payment-handler-options";
export type { PaginationOptions } from "./pagination-options";
export type { SignedData } from "./signed-data";
export type { SignedMessage } from "./signed-message";
export type { Transaction } from "./transaction";
export * from "./responses";
5 changes: 0 additions & 5 deletions src/models/signed-data.ts

This file was deleted.

7 changes: 4 additions & 3 deletions src/models/signed-message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { SignedData } from "./signed-data";
/** The interface for the signed message that can send data to the server nodes. */

/** The interface for user authenticated messages. */
export interface SignedMessage<T> extends SignedData<T> {
export interface SignedMessage<T> {
message: T;
node_identifier: string;
signature: string;
}
14 changes: 0 additions & 14 deletions tests/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,6 @@ describe("Account", () => {
);
});

it("createSignedData(data)", () => {
const account = createDefaultAccount();
assertAccountBasics(account);
assertAccountBasicValues(account, defaultAccount.signingKey, defaultAccount.accountNumber);
const signedData = account.createSignedData({ trust: "23.90" });
expect(signedData).toStrictEqual({
data: {
trust: "23.90",
},
signature:
"2b8d39b2eb528a8667475ac363cb2c84e5aeadef21ba07a80bc7a0c53e4b926ad79de242601b7810407da562c8092889321d7af9ca71911abc5af14538344c06",
});
});

it("createSignedMessage(data)", () => {
const account = createDefaultAccount();
assertAccountBasics(account);
Expand Down