Skip to content

Commit

Permalink
Merge pull request #63 from randlabs/override-signer-option
Browse files Browse the repository at this point in the history
Sign Transaction option: override signer
Initialize Messaging instance inside MyAlgo Connect constructor
  • Loading branch information
Alex99y committed Apr 13, 2022
2 parents d1fadaf + 1ca71c8 commit c6e69e0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
24 changes: 19 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# MyAlgo Connect Change log

## [1.1.2] - 10-01-2022
## [1.1.3] - 2022-04-13

### Added

- Added optional object parameter to the `signTransaction` method to force MyAlgoConnect to sign with a specific account

### Fixed

- Fixed error caused by undefined `window` reference when working with server side applications/frameworks such as Next.js (see related [issue](https://github.com/randlabs/communication-bridge/issues/5))

### Known issue

- MyAlgo Connect package still has the `Buffer is not defined` error (#27).

## [1.1.2] - 2022-01-10

### Added

Expand All @@ -16,7 +30,7 @@

- MyAlgo Connect package still has the `Buffer is not defined` error (#27).

## [1.1.1] - 01-09-2021
## [1.1.1] - 2021-09-01

### Added

Expand All @@ -27,7 +41,7 @@

- MyAlgo Connect package still has the `Buffer is not defined` error (#27).

## [1.1.0] - 13-07-2021
## [1.1.0] - 2021-07-13

### Added

Expand Down Expand Up @@ -63,13 +77,13 @@

- MyAlgo Connect package still has the `Buffer is not defined` error (#27).

## [1.0.1] - 08-03-2021
## [1.0.1] - 2021-03-08

### Fixes

- Exported SignedTxn (#14).
- Minor fixes

## [1.0.0] - 04-03-2021
## [1.0.0] - 2021-03-04

- Initial release.
10 changes: 8 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ export interface Options {
disableLedgerNano?: boolean;
}

export interface SignTransactionOptions {
overrideSigner?: Address;
}

export interface ConnectionSettings {
shouldSelectOneAccount?: boolean;
openManager?: boolean;
Expand All @@ -182,17 +186,19 @@ export default class MyAlgoConnect {
* @async
* @description Sign an Algorand Transaction.
* @param transaction Expect a valid Algorand transaction
* @param signOptions Sign transactions options object.
* @returns Returns signed transaction
*/
signTransaction(transaction: AlgorandTxn | EncodedTransaction): Promise<SignedTx>;
signTransaction(transaction: AlgorandTxn | EncodedTransaction, signOptions?: SignTransactionOptions): Promise<SignedTx>;

/**
* @async
* @description Sign an Algorand Transaction.
* @param transaction Expect a valid Algorand transaction array.
* @param signOptions Sign transactions options object.
* @returns Returns signed an array of signed transactions.
*/
signTransaction(transaction: (AlgorandTxn | EncodedTransaction)[]): Promise<SignedTx[]>;
signTransaction(transaction: (AlgorandTxn | EncodedTransaction)[], signOptions?: SignTransactionOptions): Promise<SignedTx[]>;

/**
* @async
Expand Down
22 changes: 19 additions & 3 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ const { sleep, prepareTxn } = require("./utils/utils");
const Errors = require("./utils/errors");

const Messaging = require("./messaging/Messaging");
const bridge = new Messaging();

/**
* @type {Messaging | null}
*/
let bridge = null;

/**
* @description Transaction hash
Expand All @@ -26,6 +30,13 @@ const bridge = new Messaging();
* @property {boolean} [disableLedgerNano] It will disable ledger nano accounts and returns only mnemonic accounts.
*/

/**
* @description Sign transaction options
* @typedef SignTransactionOptions
* @type {object}
* @property {Address} [overrideSigner] Force transactions to be signed with the specified account instead of the from/auth address.
*/

/**
* @description Connect method settings
* @typedef ConnectionSettings
Expand Down Expand Up @@ -193,6 +204,10 @@ class MyAlgoConnect {
*/
constructor(options) {

if (!bridge) {
bridge = new Messaging();
}

/**
* @access private
* @type {Messaging}
Expand Down Expand Up @@ -299,11 +314,12 @@ class MyAlgoConnect {
* @access public
* @description Open a new window to sign transaction.
* @param {Transaction|Transaction[]|EncodedTransaction|EncodedTransaction[]} transaction Transaction object or a Transaction array.
* @param {SignTransactionOptions} [signOptions] Sign transactions options object.
* (The signer account must be the same for all transactions).
* @returns {(SignedTx|SignedTx[])} Returns transaction blob or an Array of blobs, depends if the
* transaction was an object or an array.
*/
async signTransaction(transaction) {
async signTransaction(transaction, signOptions) {
let txn;

if (this.currentSigntxPopup) {
Expand All @@ -329,7 +345,7 @@ class MyAlgoConnect {
const res = await this.bridge.sendMessage(
this.currentSigntxPopup, {
method: "transaction",
params: { txn, settings: { disableLedgerNano: this.disableLedgerNano } }
params: { txn, settings: { disableLedgerNano: this.disableLedgerNano }, options: signOptions },
},
this.url, this.options
);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@randlabs/myalgo-connect",
"version": "1.1.2",
"version": "1.1.3",
"description": "",
"main": "index.js",
"types": "index.d.ts",
Expand Down

0 comments on commit c6e69e0

Please sign in to comment.