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

Updates to algorand.enable() #473

Merged
merged 8 commits into from
Jan 31, 2023
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
4 changes: 2 additions & 2 deletions docs/dApp-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,9 @@ Some of the following error codes may be returned when interacting with AlgoSign
| 4000 | An unknown error occured. | N/A |
| 4001 | The user rejected the signature request. | N/A |
| 4100 | The requested operation and/or account has not been authorized by the user. | This is usually due to the connection between the dApp and the wallet becoming stale and the user [needing to reconnect](connection-issues.md). Otherwise, it may signal that you are trying to sign with private keys not found on AlgoSigner. |
| 4200 | The wallet does not support the requested operation. | N/A |
| 4200 | The wallet does not support the requested operation. | Users need to have imported or created an account on AlgoSigner before connecting to dApps, as well as succesfully having configured any custom networks required. |
| 4201 | The wallet does not support signing that many transactions at a time. | The max number of transactions per group is 16. For Ledger devices, they currently can't sign more than one transaction at the same time. |
| 4202 | The wallet was not initialized properly beforehand. | Users need to have imported or created an account on AlgoSigner before connecting to dApps. |
| 4202 | The wallet was not initialized properly beforehand. | The extension user has not authorized requests from this website. |
| 4300 | The input provided is invalid. | AlgoSigner rejected some of the transactions due to invalid fields. |
| 4400 | Some transactions were not sent properly. | Some, but not all of the transactions were able to be posted to the network. The IDs of the succesfully posted transactions as well as information on the failing ones are provided on the error.

Expand Down
8 changes: 4 additions & 4 deletions docs/legacy-dApp-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ AlgoSigner.send({
- A non-matching ledger name will result in a error:
- The provided ledger is not supported (Code: 4200).
- An empty request will result with an error:
- Ledger not provided. Please use a base ledger: [TestNet,MainNet] or an available custom one [{"name":"Theta","genesisId":"thetanet-v1.0"}].
- Transaction requests will require a valid matching "genesisId", even for custom networks.
- Ledger not provided. Please use a base ledger: [TestNet,MainNet] or an available custom one [{"name":"Theta","genesisID":"thetanet-v1.0"}].
- Transaction requests will require a valid matching "genesisID", even for custom networks.

## Signature Rejection Messages

Expand All @@ -536,9 +536,9 @@ AlgoSigner may return some of the following error codes when requesting signatur
| 4000 | An unknown error occured. | N/A |
| 4001 | The user rejected the signature request. | N/A |
| 4100 | The requested operation and/or account has not been authorized by the user. | This is usually due to the connection between the dApp and the wallet becoming stale and the user [needing to reconnect](connection-issues.md). Otherwise, it may signal that you are trying to sign with private keys not found on AlgoSigner. |
| 4200 | The wallet does not support the requested operation. | N/A |
| 4200 | The wallet does not support the requested operation. | Users need to have imported or created an account on AlgoSigner before connecting to dApps, as well as succesfully having configured any custom networks required. |
| 4201 | The wallet does not support signing that many transactions at a time. | The max number of transactions per group is 16. For Ledger devices, they can't sign more than one transaction at the same time. |
| 4202 | The wallet was not initialized properly beforehand. | Users need to have imported or created an account on AlgoSigner before connecting to dApps |
| 4202 | The wallet was not initialized properly beforehand. | The extension user has not authorized requests from this website. |
| 4300 | The input provided is invalid. | AlgoSigner rejected some of the transactions due to invalid fields. |

Additional information, if available, would be provided in the `data` field of the error object.
Expand Down
25 changes: 14 additions & 11 deletions packages/common/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ export class RequestError {
'The extension user does not authorize the request.',
4001
);
static EnableRejected = (data: object): RequestError => new RequestError(
'The extension user does not authorize the request.',
4001,
data
);
static SiteNotAuthorizedByUser = new RequestError(
'The extension user has not authorized requests from this website.',
4100
);
static EnableRejected = (data: object): RequestError =>
new RequestError('The extension user does not authorize the request.', 4001, data);
static NoMnemonicAvailable = (address: string): RequestError =>
new RequestError(
`The user does not possess the required private key to sign with for address: "${address}".`,
Expand All @@ -32,7 +25,13 @@ export class RequestError {
`No matching account found on AlgoSigner for address "${address}" on network ${ledger}.`,
4100
);
static NoLedgerProvided = (base: string, injected: string): RequestError =>
new RequestError(
`Ledger not provided. Please use a base ledger: [${base}] or an available custom one ${injected}.`,
4200
);
static UnsupportedLedger = new RequestError('The provided ledger is not supported.', 4200);
static UnsupportedNetwork = new RequestError('The provided network is not supported.', 4200);
static PendingTransaction = new RequestError('Another query processing', 4201);
static LedgerMultipleGroups = new RequestError(
'Ledger hardware device signing is only available for one transaction group at a time.',
Expand All @@ -44,6 +43,10 @@ export class RequestError {
);
static AlgoSignerNotInitialized = new RequestError(
'AlgoSigner was not initialized properly beforehand.',
4200
);
static SiteNotAuthorizedByUser = new RequestError(
'The extension user has not authorized requests from this website.',
4202
);
static InvalidFields = (data?: any): RequestError =>
Expand Down Expand Up @@ -129,8 +132,8 @@ export class RequestError {
'All transactions provided in a same group need to have matching group IDs.',
4300
);
static NoDifferentLedgers = new RequestError(
'All transactions need to belong to the same ledger.',
static NoDifferentNetworks = new RequestError(
'All transactions need to belong to the same network.',
4300
);
static PartiallySuccessfulPost = (successTxnIDs: string[], data: any): PostError =>
Expand Down
12 changes: 6 additions & 6 deletions packages/common/src/types/ledgers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export class LedgerTemplate {
name: string;
readonly isEditable: boolean;
genesisId?: string;
genesisID?: string;
genesisHash?: string;
symbol?: string;
algodUrl?: string;
Expand All @@ -14,15 +14,15 @@ export class LedgerTemplate {

constructor({
name,
genesisId,
genesisID,
genesisHash,
symbol,
algodUrl,
indexerUrl,
headers,
}: {
name: string;
genesisId?: string;
genesisID?: string;
genesisHash?: string;
symbol?: string;
algodUrl?: string;
Expand All @@ -34,7 +34,7 @@ export class LedgerTemplate {
}

this.name = name;
this.genesisId = genesisId || 'mainnet-v1.0';
this.genesisID = genesisID || 'mainnet-v1.0';
this.genesisHash = genesisHash;
this.symbol = symbol;
this.algodUrl = algodUrl;
Expand All @@ -49,12 +49,12 @@ export function getBaseSupportedLedgers(): Array<LedgerTemplate> {
return [
new LedgerTemplate({
name: 'MainNet',
genesisId: 'mainnet-v1.0',
genesisID: 'mainnet-v1.0',
genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=',
}),
new LedgerTemplate({
name: 'TestNet',
genesisId: 'testnet-v1.0',
genesisID: 'testnet-v1.0',
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=',
}),
];
Expand Down
12 changes: 6 additions & 6 deletions packages/extension/src/background/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Settings {
for (var i = 0; i < injectedNetworkKeys.length; i++) {
injectedNetworks.push({
name: this.backend_settings.InjectedNetworks[injectedNetworkKeys[i]].name,
genesisId: this.backend_settings.InjectedNetworks[injectedNetworkKeys[i]].genesisId,
genesisID: this.backend_settings.InjectedNetworks[injectedNetworkKeys[i]].genesisID,
});
}

Expand Down Expand Up @@ -86,9 +86,9 @@ export class Settings {
}
}

// Add the algod links defaulting the url to one based on the genesisId
// Add the algod links defaulting the url to one based on the genesisID
let defaultUrl = 'https://algosigner.api.purestake.io/mainnet';
if (ledger.genesisId && ledger.genesisId.indexOf('testnet') > -1) {
if (ledger.genesisID && ledger.genesisID.indexOf('testnet') > -1) {
defaultUrl = 'https://algosigner.api.purestake.io/testnet';
}

Expand Down Expand Up @@ -125,10 +125,10 @@ export class Settings {
}

public static addInjectedNetwork(ledger: LedgerTemplate) {
// Initialize the injected network with the genesisId and a name that mimics the ledger for reference
// Initialize the injected network with the genesisID and a name that mimics the ledger for reference
this.backend_settings.InjectedNetworks[ledger.name] = {
name: ledger.name,
genesisId: ledger.genesisId || '',
genesisID: ledger.genesisID || '',
};

this.setInjectedHeaders(ledger);
Expand All @@ -149,7 +149,7 @@ export class Settings {
this.deleteInjectedNetwork(previousName);
this.backend_settings.InjectedNetworks[targetName] = {};
}
this.backend_settings.InjectedNetworks[targetName].genesisId = updatedLedger.genesisId;
this.backend_settings.InjectedNetworks[targetName].genesisID = updatedLedger.genesisID;
this.backend_settings.InjectedNetworks[targetName].symbol = updatedLedger.symbol;
this.backend_settings.InjectedNetworks[targetName].genesisHash =
updatedLedger.genesisHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('wallet flow', () => {
{
algodUrl: undefined,
genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=',
genesisId: 'mainnet-v1.0',
genesisID: 'mainnet-v1.0',
headers: undefined,
indexerUrl: undefined,
isEditable: false,
Expand All @@ -108,7 +108,7 @@ describe('wallet flow', () => {
{
algodUrl: undefined,
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=',
genesisId: 'testnet-v1.0',
genesisID: 'testnet-v1.0',
headers: undefined,
indexerUrl: undefined,
isEditable: false,
Expand Down Expand Up @@ -142,7 +142,7 @@ describe('wallet flow', () => {
{
algodUrl: undefined,
genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=',
genesisId: 'mainnet-v1.0',
genesisID: 'mainnet-v1.0',
headers: undefined,
indexerUrl: undefined,
isEditable: false,
Expand All @@ -152,7 +152,7 @@ describe('wallet flow', () => {
{
algodUrl: undefined,
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=',
genesisId: 'testnet-v1.0',
genesisID: 'testnet-v1.0',
headers: undefined,
indexerUrl: undefined,
isEditable: false,
Expand Down
10 changes: 5 additions & 5 deletions packages/extension/src/background/messaging/internalMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ValidationStatus } from '../utils/validator';
import {
calculateEstimatedFee,
getValidatedTxnWrap,
getLedgerFromGenesisId,
getLedgerFromGenesisID,
getLedgerFromMixedGenesis,
} from '../transaction/actions';
import { BaseValidatedTxnWrap } from '../transaction/baseValidatedTxnWrap';
Expand Down Expand Up @@ -100,7 +100,7 @@ export class InternalMethods {

// Checks if an account for the given address exists on AlgoSigner for a given ledger.
public static checkAccountIsImported(genesisID: string, address: string): void {
const ledger: string = getLedgerFromGenesisId(genesisID);
const ledger: string = getLedgerFromGenesisID(genesisID);
let found = false;
for (let i = session.wallet[ledger].length - 1; i >= 0; i--) {
if (session.wallet[ledger][i].address === address) {
Expand Down Expand Up @@ -500,7 +500,7 @@ export class InternalMethods {
sendResponse({ message: message });
} else if (session.txnRequest.source === 'ui') {
// If this is an UI transaction then we need to submit to the network
const ledger = getLedgerFromGenesisId(decodedTxn.txn.genesisID);
const ledger = getLedgerFromGenesisID(decodedTxn.txn.genesisID);

const algod = this.getAlgod(ledger);
algod
Expand Down Expand Up @@ -1044,7 +1044,7 @@ export class InternalMethods {
const targetName = previousName ? previousName : params['name'].toLowerCase();
const addedLedger = new LedgerTemplate({
name: params['name'],
genesisId: params['genesisId'],
genesisID: params['genesisID'],
genesisHash: params['genesisHash'],
symbol: params['symbol'],
algodUrl: params['algodUrl'],
Expand All @@ -1070,7 +1070,7 @@ export class InternalMethods {
if (!defaultLedgers.some((dledg) => dledg.uniqueName === matchingLedger.uniqueName)) {
Settings.updateInjectedNetwork(addedLedger, previousName);
matchingLedger.name = addedLedger.name;
matchingLedger.genesisId = addedLedger.genesisId;
matchingLedger.genesisID = addedLedger.genesisID;
matchingLedger.symbol = addedLedger.symbol;
matchingLedger.genesisHash = addedLedger.genesisHash;
matchingLedger.algodUrl = addedLedger.algodUrl;
Expand Down
Loading