Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #305 from PureStake/develop
Browse files Browse the repository at this point in the history
Patch 1.6.5
  • Loading branch information
PureBrent authored Oct 1, 2021
2 parents f5cd03c + df8eed4 commit 31cb57e
Show file tree
Hide file tree
Showing 21 changed files with 727 additions and 296 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ Added ability to use a Ledger device to add public addresses into AlgoSigner and
- Allow for zero Algo pay transactions in UI
- Fix stall for `Axfer` in txs list when decimals can't be obtained from the asset

### 1.6.5 Patch
- Fixed duplicate Port on Custom Network calls
- Added support for receiving an array of arrays when using `signTxn()`
- Each inner array should still contain transactions **belonging to a same group**
- Updated error message when providing an incorrect format of transactions to reflect this change

## New Users

- Watch [Getting Started with AlgoSigner](https://youtu.be/tG-xzG8r770)
Expand Down
39 changes: 38 additions & 1 deletion docs/dApp-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ AlgoSigner.signTxn([
]);
```

**NOTE:** Even though the method accepts an array of transactions, it requires atomic transactions with groupId and will error on non-atomic groups.
**NOTE:** Even though the method accepts an array of transactions, it requires atomic transactions that have a groupId and will error on non-atomic groups.

**Response**

Expand Down Expand Up @@ -221,6 +221,42 @@ let signedTxs = await AlgoSigner.signTxn([
},
]);
```
Alternatively, you can provide multiple arrays of transactions at once. Same rules regarding the contents of the groups apply.

**Request**

```js
AlgoSigner.signTxn([
[
{
txn: 'iqNhbXRko2ZlZc0D6KJmds4A259Go2dlbqx0ZXN0bmV0LXYxLjCiZ2jEIEhjtRiks8hOyBDyLU8QgcsPcfBZp6wg3sYvf3DlCToio2dycMQgdsLAGqgrtwqqQS4UEN7O8CZHjfhPTwLHrB1A2pXwvKGibHbOANujLqNyY3bEIK0TEDcptY0uFvk2V5LDVzRfdz7O4freYHEuZbpI+6hMo3NuZMQglmyhKUPeU2KALzt/Jcs0GQ55k2vsqZ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cs0GQ55k2vsqZ4pGeNlzpnYLbukdHlwZaRhZnJ6"
}
]
]
```

The signed transactions can then be sent using the SDK (example below) or using the [AlgoSigner.send()](#algosignersend-ledger-mainnettestnet-txblob-) method.

Expand Down Expand Up @@ -439,6 +475,7 @@ The dApp may return the following errors in case of users rejecting requests, or
InvalidTransactionParams = '[RequestErrors.InvalidTransactionParams] Invalid transaction parameters.',
UnsupportedAlgod = '[RequestErrors.UnsupportedAlgod] The provided method is not supported.',
UnsupportedLedger = '[RequestErrors.UnsupportedLedger] The provided ledger is not supported.',
InvalidFormat = '[RequestErrors.InvalidFormat] Please provide an array of either valid transaction objects or nested arrays of valid transaction objects.',
Undefined = '[RequestErrors.Undefined] An undefined error occurred.',
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "algosigner",
"version": "1.6.4",
"version": "1.6.5",
"author": "https://developer.purestake.io",
"description": "Sign Algorand transactions in your browser with PureStake.",
"repository": "https://github.com/PureStake/algosigner",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@algosigner/common",
"version": "1.6.4",
"version": "1.6.5",
"author": "https://developer.purestake.io",
"description": "Common library functions for AlgoSigner.",
"repository": "https://github.com/PureStake/algosigner",
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum RequestErrors {
InvalidTransactionParams = '[RequestErrors.InvalidTransactionParams] Invalid transaction parameters.',
UnsupportedAlgod = '[RequestErrors.UnsupportedAlgod] The provided method is not supported.',
UnsupportedLedger = '[RequestErrors.UnsupportedLedger] The provided ledger is not supported.',
InvalidFormat = '[RequestErrors.InvalidFormat] Please provide an array of either valid transaction objects or nested arrays of valid transaction objects.',
Undefined = '[RequestErrors.Undefined] An undefined error occurred.',
}

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "algosigner-crypto",
"version": "1.6.4",
"version": "1.6.5",
"author": "https://developer.purestake.io",
"description": "Cryptographic wrapper for saving and retrieving extention information in Algosigner.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@algosigner/dapp",
"version": "1.6.4",
"version": "1.6.5",
"author": "https://developer.purestake.io",
"repository": "https://github.com/PureStake/algosigner",
"license": "MIT",
Expand Down
30 changes: 17 additions & 13 deletions packages/dapp/src/fn/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,33 @@ export class Task extends Runtime implements ITask {
}

/**
* @param transactions array of valid wallet transaction objects
* @returns array of signed transactions
* @param transactionsOrGroups array or nested array of grouped transaction objects
* @returns array or nested array of signed transactions
*/
signTxn(
transactions: Array<WalletTransaction>,
transactionsOrGroups: Array<WalletTransaction>,
error: RequestErrors = RequestErrors.None
): Promise<JsonPayload> {
const formatError = new Error(
'There was a problem with the transaction(s) recieved. Please provide an array of valid transaction objects.'
);
if (!Array.isArray(transactions) || !transactions.length) throw formatError;
transactions.forEach((walletTx) => {
const formatError = new Error(RequestErrors.InvalidFormat);
// We check for empty arrays
if (!Array.isArray(transactionsOrGroups) || !transactionsOrGroups.length) throw formatError;
transactionsOrGroups.forEach((txOrGroup) => {
// We check for no null values and no empty nested arrays
if (
walletTx === null ||
typeof walletTx !== 'object' ||
walletTx.txn === null ||
!walletTx.txn.length
txOrGroup === null ||
txOrGroup === undefined ||
(!Array.isArray(txOrGroup) && typeof txOrGroup === 'object' &&
(!txOrGroup.txn || (txOrGroup.txn && !txOrGroup.txn.length))
) ||
(Array.isArray(txOrGroup) &&
(!txOrGroup.length || (txOrGroup.length && !txOrGroup.every((tx) => tx !== null)))
)
)
throw formatError;
});

const params = {
transactions: transactions,
transactionsOrGroups: transactionsOrGroups,
};
return MessageBuilder.promise(JsonRpcMethod.SignWalletTransaction, params, error);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "AlgoSigner",
"author": "https://developer.purestake.io",
"version": "1.6.4",
"version": "1.6.5",
"description": "Algorand Wallet Extension | Send & Receive ALGOs | Sign dApp Transactions",
"icons": {
"48": "icon.png"
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "algosigner-extension",
"version": "1.6.4",
"version": "1.6.5",
"author": "https://developer.purestake.io",
"repository": "https://github.com/PureStake/algosigner",
"license": "MIT",
Expand Down
30 changes: 7 additions & 23 deletions packages/extension/src/background/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging from '@algosigner/common/logging';
import { LedgerTemplate } from '@algosigner/common/types/ledgers';
import { Ledger, Backend, API } from './messaging/types';
import { parseUrlServerAndPort } from './utils/networkUrlParser';

export class Settings {
static backend: Backend = Backend.PureStake;
Expand Down Expand Up @@ -91,36 +91,20 @@ export class Settings {
}

// Setup port splits for algod and indexer - used in sandbox installs
let algodUrlPort = '';
let indexerUrlPort = '';

try {
const algodUrlObj = new URL(ledger.algodUrl);
algodUrlPort = algodUrlObj.port;
}
catch {
logging.log(`Unable to parse the URL ${ledger.algodUrl}`)
}

try {
const indexerUrlObj = new URL(ledger.indexerUrl);
indexerUrlPort = indexerUrlObj.port;
}
catch {
logging.log(`Unable to parse the URL ${ledger.indexerUrl}`)
}
const parsedAlgodUrlObj = parseUrlServerAndPort(ledger.algodUrl)
const parsedIndexerUrlObj = parseUrlServerAndPort(ledger.indexerUrl);

this.backend_settings.InjectedNetworks[ledger.name][API.Algod] = {
url: ledger.algodUrl || `${defaultUrl}/algod`,
port: algodUrlPort,
url: parsedAlgodUrlObj.server || `${defaultUrl}/algod`,
port: parsedAlgodUrlObj.port,
apiKey: headersAlgod || headers,
headers: headersAlgod || headers,
};

// Add the indexer links
this.backend_settings.InjectedNetworks[ledger.name][API.Indexer] = {
url: ledger.indexerUrl || `${defaultUrl}/indexer`,
port: indexerUrlPort,
url: parsedIndexerUrlObj.server || `${defaultUrl}/indexer`,
port: parsedIndexerUrlObj.port,
apiKey: headersIndexer || headers,
headers: headersIndexer || headers,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export class InternalMethods {
);
return true;
}

public static [JsonRpcMethod.LedgerGetSessionTxn](request: any, sendResponse: Function) {
if (session.txnWrap && 'body' in session.txnWrap) {
// The transaction may contain source and JSONRPC info, the body.params will be the transaction validation object
Expand Down Expand Up @@ -455,6 +456,7 @@ export class InternalMethods {
});
return true;
}

public static [JsonRpcMethod.AccountDetails](request: any, sendResponse: Function) {
const { ledger, address } = request.body.params;
const algod = this.getAlgod(ledger);
Expand Down Expand Up @@ -935,6 +937,7 @@ export class InternalMethods {
sendResponse({ error: e.message });
}
}

public static [JsonRpcMethod.GetLedgers](request: any, sendResponse: Function) {
getAvailableLedgersExt((availableLedgers) => {
sendResponse(availableLedgers);
Expand Down
Loading

0 comments on commit 31cb57e

Please sign in to comment.