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 #277 from PureStake/master
Browse files Browse the repository at this point in the history
1.6.1 Patch
  • Loading branch information
Jan Marcano authored Aug 6, 2021
2 parents c6b3618 + d087cc5 commit 14d6831
Show file tree
Hide file tree
Showing 50 changed files with 313 additions and 251 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ Added ability to use a Ledger device to add public addresses into AlgoSigner and
- Modify transactions without an amount to default to 0
- Fixed issue with creating assets that have zero decimals

### 1.6.1 Patch
- `BigInt` support for `amount` and `assetTotal`
- Algorand JS SDK `v1.9.1` support
- Various improvements regarding Transaction fields validations and Signing UI clarity

## New Users

- Watch [Getting Started with AlgoSigner](https://youtu.be/tG-xzG8r770)
Expand Down
2 changes: 1 addition & 1 deletion docs/dApp-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ With the release of v2 signing, developers coding to the standard will be able t

### Developing a dApp

- Read [v2 dApp Integration Guide](docs/dApp-integration.md)
- Read [v2 dApp Integration Guide](dApp-integration.md)
2 changes: 1 addition & 1 deletion docs/dApp-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ AlgoSigner.send({

## Custom Networks

- Custom networks beta support is now in AlgoSigner. [Setup Guide](docs/add-network.md)
- Custom networks beta support is now in AlgoSigner. [Setup Guide](add-network.md)
- AlgoSigner.accounts(ledger) has changed such that calls now accept names that have been added to the user's custom network list as valid ledger names.
- A non-matching ledger name will result in a error:
- [RequestErrors.UnsupportedLedger] The provided ledger is not supported.
Expand Down
2 changes: 1 addition & 1 deletion docs/legacy-dApp-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Sent in transactions will be validated against the Algorand JS SDK transaction t

Proxied requests are passed through to an API service - currently set to the PureStake API service. Endpoints available are limited to what the service exposes. The API backend may be configured by advanced users and is not guaranteed to respond as expected.

This page documents the legacy AlgoSigner.sign() method, will be deprecated in a future release in favor of AlgoSigner.signTxn() covered [here](docs/dApp-integration.md).
This page documents the legacy AlgoSigner.sign() method, will be deprecated in a future release in favor of AlgoSigner.signTxn() covered [here](dApp-integration.md).

_The v1 Atomic transaction functionality will start warning extension users in the next major release and be deprecated entirely in two releases._

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.0",
"version": "1.6.1",
"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.0",
"version": "1.6.1",
"author": "https://developer.purestake.io",
"description": "Common library functions for AlgoSigner.",
"repository": "https://github.com/PureStake/algosigner",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/interfaces/acfg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IBaseTx } from './baseTx';
export interface IAssetConfigTx extends IBaseTx {
type: string, //"acfg"
assetIndex: number, //uint64 "caid" For re-configure or destroy transactions, this is the unique asset ID. On asset creation, the ID is set to zero.
assetTotal?: number, //uint64 "t" The total number of base units of the asset to create. This number cannot be changed.
assetTotal?: BigInt, //uint64 "t" The total number of base units of the asset to create. This number cannot be changed.
assetDecimals?: number, //uint32 "dc" The number of digits to use after the decimal point when displaying the asset. If 0, the asset is not divisible. If 1, the base unit of the asset is in tenths. If 2, the base unit of the asset is in hundredths.
assetDefaultFrozen?: boolean, //bool "df" True to freeze holdings for this asset by default.
assetUnitName?: string, //string "un" The name of a unit of this asset. Supplied on creation. Example: USDT
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/interfaces/acfg_create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { IBaseTx } from './baseTx';
// prettier-ignore
export interface IAssetCreateTx extends IBaseTx {
type: string, //"acfg"
assetTotal: number, //uint64 "t" The total number of base units of the asset to create. This number cannot be changed.
assetDecimals?: number, //uint32 "dc" The number of digits to use after the decimal point when displaying the asset. If 0, the asset is not divisible. If 1, the base unit of the asset is in tenths. If 2, the base unit of the asset is in hundredths.
assetTotal: BigInt, //uint64 "t" The total number of base units of the asset to create. This number cannot be changed.
assetDecimals?: number, //uint32 "dc" The number of digits to use after the decimal point when displaying the asset. If 0, the asset is not divisible. If 1, the base unit of the asset is in tenths. If 2, the base unit of the asset is in hundredths.
assetDefaultFrozen?: boolean, //bool "df" True to freeze holdings for this asset by default.
assetUnitName?: string, //string "un" The name of a unit of this asset. Supplied on creation. Example: USDT
assetName?: string, //string "an" The name of the asset. Supplied on creation. Example: Tether
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/interfaces/afrz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export interface IAssetFreezeTx extends IBaseTx {
type: string, //"afrz"
assetIndex: number, //uint64 "xaid" The unique ID of the asset to be transferred.
freezeAccount: string, //Address "fadd" The address of the account whose asset is being frozen or unfrozen.
freezeState: boolean //bool "afrz" True to freeze the asset.
freezeState?: boolean //bool "afrz" True to freeze the asset.
}
2 changes: 1 addition & 1 deletion packages/common/src/interfaces/axfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IBaseTx } from './baseTx';
export interface IAssetTransferTx extends IBaseTx {
type: string, //"axfer"
assetIndex: number, //uint64 "xaid" The unique ID of the asset to be transferred.
amount: number, //uint64 "aamt" The amount of the asset to be transferred. A zero amount transferred to self allocates that asset in the account's Asset map.
amount: BigInt, //uint64 "aamt" The amount of the asset to be transferred. A zero amount transferred to self allocates that asset in the account's Asset map.
to: string, //Address "arcv" The recipient of the asset transfer.
closeRemainderTo?: string, //Address "aclose" Specify this field to remove the asset holding from the sender account and reduce the account's minimum balance.
}
2 changes: 1 addition & 1 deletion packages/common/src/interfaces/axfer_accept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import { IBaseTx } from './baseTx';
export interface IAssetAcceptTx extends IBaseTx {
type: string, //"axfer"
assetIndex: number, //uint64 "xaid" The unique ID of the asset to be transferred.
amount?: number, //uint64 "aamt" The amount of the asset to be transferred. A zero amount transferred to self allocates that asset in the account's Asset map.
amount?: BigInt, //uint64 "aamt" The amount of the asset to be transferred. A zero amount transferred to self allocates that asset in the account's Asset map.
to: string, //Address "arcv" The recipient of the asset transfer. Must be self for Asset Accept.
}
2 changes: 1 addition & 1 deletion packages/common/src/interfaces/axfer_clawback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IBaseTx } from './baseTx';
export interface IAssetClawbackTx extends IBaseTx {
type: string, //"axfer"
assetIndex: number, //uint64 "xaid" The unique ID of the asset to be transferred.
amount: number, //uint64 "aamt" The amount of the asset to be transferred. A zero amount transferred to self allocates that asset in the account's Asset map.
amount: BigInt, //uint64 "aamt" The amount of the asset to be transferred. A zero amount transferred to self allocates that asset in the account's Asset map.
closeRemainderTo?: string, //Address "aclose" Specify this field to remove the asset holding from the sender account and reduce the account's minimum balance.
assetRevocationTarget: string, //Address "asnd" The address from which the funds will be withdrawn.
to: string, //Address
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/interfaces/pay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import { IBaseTx } from './baseTx';
export interface IPaymentTx extends IBaseTx {
type: string, //"pay"
to: string, //Address "rcv" The address of the account that receives the amount.
amount: number, //uint64 "amt" The total amount to be sent in microAlgos.
amount: BigInt, //uint64 "amt" The total amount to be sent in microAlgos.
closeRemainderTo?: string, //Address "close" When set, it indicates that the transaction is requesting that the Sender account should be closed, and all remaining funds, after the fee and amount are paid, be transferred to this address.
}
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.0",
"version": "1.6.1",
"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.0",
"version": "1.6.1",
"author": "https://developer.purestake.io",
"repository": "https://github.com/PureStake/algosigner",
"license": "MIT",
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.0",
"version": "1.6.1",
"description": "Algorand Wallet Extension | Send & Receive ALGOs | Sign dApp Transactions",
"icons": {
"48": "icon.png"
Expand Down
6 changes: 3 additions & 3 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "algosigner-extension",
"version": "1.6.0",
"version": "1.6.1",
"author": "https://developer.purestake.io",
"repository": "https://github.com/PureStake/algosigner",
"license": "MIT",
Expand All @@ -15,12 +15,12 @@
"jest-webextension-mock": "^3.6.1",
"ts-jest": "^27.0.0",
"ts-loader": "^7.0.5",
"typescript": "^3.9.7",
"typescript": "^4.3.2",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.11"
},
"dependencies": {
"algosdk": "1.8.1"
"algosdk": "1.9.1"
},
"scripts": {
"build": "npm run clean && npm run bundle && npm run copy",
Expand Down
7 changes: 0 additions & 7 deletions packages/extension/src/background/account/createAccount.js

This file was deleted.

11 changes: 6 additions & 5 deletions packages/extension/src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';
const algosdk = require("algosdk");
import encryptionWrap from "./encryptionWrap";
import createNewAccount from "./account/createAccount.js";
import { TransactionType } from "@algosigner/common/types/transaction";

(BigInt as any).prototype.toJSON = function () {
return this.toString();
};

import Background from './background';
Background.start();
Background.start();
22 changes: 12 additions & 10 deletions packages/extension/src/background/messaging/internalMethods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { JsonRpcMethod } from '@algosigner/common/messaging/types';
import { Ledger } from './types';
import encryptionWrap from '../encryptionWrap';
import { InternalMethods } from './internalMethods';
/* eslint-disable-next-line @typescript-eslint/no-var-requires */
const algosdk = require('algosdk');
import algosdk from 'algosdk';

jest.mock('../encryptionWrap');

Expand Down Expand Up @@ -295,7 +294,7 @@ describe('algosdk methods', () => {
};
const sendResponse = jest.fn();

const fooSpy = jest.spyOn(algosdk, 'Algodv2');
const fooSpy = jest.spyOn(algosdk as any, 'Algodv2');
fooSpy.mockImplementationOnce(() => {
return {
accountInformation: () => {
Expand Down Expand Up @@ -362,8 +361,7 @@ describe('algosdk methods', () => {
'sender': 'GD64YIY3TWGDMCNPP553DZPPR6LDUSFQOIJVFDPPXWEG3FVOJCCDBBHU5A',
'sender-rewards': 0,
'signature': {
sig:
'ZjD8XY8CxKnK/oXvc1bxKve2KQsxi5Yavmv9P84d/jtX10eux5nBqjoPowu3+Bs5xH3jRSNCmYgHmjZlEdD5DA==',
sig: 'ZjD8XY8CxKnK/oXvc1bxKve2KQsxi5Yavmv9P84d/jtX10eux5nBqjoPowu3+Bs5xH3jRSNCmYgHmjZlEdD5DA==',
},
'tx-type': 'pay',
},
Expand Down Expand Up @@ -401,16 +399,20 @@ describe('algosdk methods', () => {
{
type: mockAlgodResponse['top-transactions'][0]['txn']['type'],
amount: mockAlgodResponse['top-transactions'][0]['txn']['amt'],
sender: algosdk.encodeAddress(mockAlgodResponse['top-transactions'][0]['txn']['snd']),
receiver: algosdk.encodeAddress(mockAlgodResponse['top-transactions'][0]['txn']['rcv']),
sender: algosdk.encodeAddress(
new Uint8Array(mockAlgodResponse['top-transactions'][0]['txn']['snd'])
),
receiver: algosdk.encodeAddress(
new Uint8Array(mockAlgodResponse['top-transactions'][0]['txn']['rcv'])
),
assetSender: undefined,
assetName: undefined,
id: undefined,
},
],
};

const indexerSpy = jest.spyOn(algosdk, 'Indexer');
const indexerSpy = jest.spyOn(algosdk as any, 'Indexer');
indexerSpy.mockImplementationOnce(() => {
return {
lookupAccountTransactions: () => {
Expand All @@ -424,7 +426,7 @@ describe('algosdk methods', () => {
};
});

const algodSpy = jest.spyOn(algosdk, 'Algodv2');
const algodSpy = jest.spyOn(algosdk as any, 'Algodv2');
algodSpy.mockImplementationOnce(() => {
return {
pendingTransactionByAddress: () => {
Expand Down Expand Up @@ -487,7 +489,7 @@ describe('algosdk methods', () => {
'current-round': 8775362,
};

const fooSpy = jest.spyOn(algosdk, 'Indexer');
const fooSpy = jest.spyOn(algosdk as any, 'Indexer');
fooSpy.mockImplementationOnce(() => {
return {
lookupAssetByID: () => {
Expand Down
24 changes: 9 additions & 15 deletions packages/extension/src/background/messaging/internalMethods.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable-next-line @typescript-eslint/no-var-requires */
const algosdk = require('algosdk');

import algosdk from 'algosdk';
import { JsonRpcMethod } from '@algosigner/common/messaging/types';
import { logging } from '@algosigner/common/logging';
import { ExtensionStorage } from '@algosigner/storage/src/extensionStorage';
Expand Down Expand Up @@ -28,11 +26,11 @@ const session = new Session();
export class InternalMethods {
private static _encryptionWrap: encryptionWrap | undefined;

public static getAlgod(ledger: string) {
public static getAlgod(ledger: string): algosdk.Algodv2 {
const params = Settings.getBackendParams(ledger, API.Algod);
return new algosdk.Algodv2(params.apiKey, params.url, params.port);
}
public static getIndexer(ledger: string) {
public static getIndexer(ledger: string): algosdk.Indexer {
const params = Settings.getBackendParams(ledger, API.Indexer);
return new algosdk.Indexer(params.apiKey, params.url, params.port);
}
Expand All @@ -44,7 +42,7 @@ export class InternalMethods {
safeWallet[key] = [];

// Afterwards we can add in all the non-private keys and names into the safewallet
for (var j = 0; j < wallet[key].length; j++) {
for (let j = 0; j < wallet[key].length; j++) {
const { address, name } = wallet[key][j];
safeWallet[key].push({
address: address,
Expand Down Expand Up @@ -326,7 +324,7 @@ export class InternalMethods {
public static [JsonRpcMethod.LedgerSendTxnResponse](request: any, sendResponse: Function) {
if (session.txnWrap && 'body' in session.txnWrap) {
const txnBuf = Buffer.from(request.body.params.txn, 'base64');
const decodedTxn = algosdk.decodeSignedTransaction(txnBuf);
const decodedTxn = algosdk.decodeSignedTransaction(txnBuf) as any;
const signedTxnEntries = Object.entries(decodedTxn.txn).sort();

// Get the session transaction
Expand Down Expand Up @@ -372,12 +370,11 @@ export class InternalMethods {
}
// If this is a ui transaction then we need to also submit
else if (session.txnWrap.source === 'ui') {
const txHeaders = { 'Content-Type': 'application/x-binary' };
const ledger = getLedgerFromGenesisId(decodedTxn.txn.genesisID);

const algod = this.getAlgod(ledger);
algod
.sendRawTransaction(txnBuf, txHeaders)
.sendRawTransaction(txnBuf)
.do()
.then((resp: any) => {
sendResponse({ txId: resp.txId });
Expand Down Expand Up @@ -667,7 +664,7 @@ export class InternalMethods {
public static [JsonRpcMethod.SignSendTransaction](request: any, sendResponse: Function) {
const { ledger, address, passphrase, txnParams } = request.body.params;
this._encryptionWrap = new encryptionWrap(passphrase);
var algod = this.getAlgod(ledger);
const algod = this.getAlgod(ledger);

this._encryptionWrap.unlock(async (unlockedValue: any) => {
if ('error' in unlockedValue) {
Expand All @@ -687,6 +684,7 @@ export class InternalMethods {
const params = await algod.getTransactionParams().do();
const txn = {
...txnParams,
amount: BigInt(txnParams.amount),
fee: params.fee,
firstRound: params.firstRound,
lastRound: params.lastRound,
Expand All @@ -696,10 +694,6 @@ export class InternalMethods {

if ('note' in txn) txn.note = new Uint8Array(Buffer.from(txn.note));

const txHeaders = {
'Content-Type': 'application/x-binary',
};

let transactionWrap: BaseValidatedTxnWrap = undefined;
try {
transactionWrap = getValidatedTxnWrap(txn, txn['type']);
Expand Down Expand Up @@ -775,7 +769,7 @@ export class InternalMethods {
}

algod
.sendRawTransaction(signedTxn.blob, txHeaders)
.sendRawTransaction(signedTxn.blob)
.do()
.then((resp: any) => {
sendResponse({ txId: resp.txId });
Expand Down
Loading

0 comments on commit 14d6831

Please sign in to comment.