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

FOR REVIEW ONLY: js-algorand-sdk v3.0.0-beta.1 #891

Closed
wants to merge 3 commits into from
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
19 changes: 9 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ module.exports = {
},
plugins: ['@typescript-eslint', 'eslint-plugin-tsdoc'],
rules: {
'no-restricted-globals': [
'error',
{
// This is to ensure that we use the 'buffer' package in the browser. In Node it doesn't
// make a difference.
name: 'Buffer',
message:
"Explictly import Buffer with `import { Buffer } from 'buffer'`",
},
],
'no-constant-condition': ['error', { checkLoops: false }],
'no-restricted-syntax': ['error', 'LabeledStatement', 'WithStatement'],
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
Expand Down Expand Up @@ -68,4 +58,13 @@ module.exports = {
'tests/cucumber/browser/build/',
'tests/browser/bundle.*',
],
settings: {
'import/resolver': {
typescript: {
extensionAlias: {
'.js': ['.ts', '.d.ts', '.js'],
},
},
},
},
};
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/client/v2/algod/models/types.ts linguist-generated=true
src/client/v2/indexer/models/types.ts linguist-generated=true
2 changes: 1 addition & 1 deletion .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
env:
RELEASE_TAG: ${{ steps.set-release.outputs.release-tag }}
run: |
rm -rf dist node_modules
rm -rf node_modules
npm ci
npm run build
NEW_HASH=$(cat dist/browser/algosdk.min.js | openssl dgst -sha384 -binary | openssl base64 -A)
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
dist/*
!dist/esm
dist/esm/*
!dist/esm/package.json

.DS_Store

.idea/
Expand All @@ -6,6 +11,7 @@
.vscode/*
!.vscode/settings.json
!.vscode/extensions.json
!.vscode/launch.json

# npm
node_modules/
Expand All @@ -23,7 +29,6 @@ tests/cucumber/browser/build
tests/browser/bundle.*

# Builds
dist/
docs/
built/

Expand Down
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"singleQuote": true
"singleQuote": true,
"trailingComma": "es5"
}
27 changes: 27 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug unit tests",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/tests/mocha.js",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/tsx",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"env": {
"NODE_ENV": "testing",
"MOCHA_TIMEOUT": "0"
},
"skipFiles": [
// Node.js internal core modules
"<node_internals>/**",
// Ignore all dependencies (optional)
"${workspaceFolder}/node_modules/**"
]
}
]
}
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ UNIT_TAGS := "$(subst :, or ,$(shell awk '{print $2}' tests/cucumber/unit.tags
INTEGRATIONS_TAGS := "$(subst :, or ,$(shell awk '{print $2}' tests/cucumber/integration.tags | paste -s -d: -))"

unit:
node_modules/.bin/cucumber-js --tags $(UNIT_TAGS) tests/cucumber/features --require-module ts-node/register --require tests/cucumber/steps/index.js
node_modules/.bin/cucumber-js --tags $(UNIT_TAGS) tests/cucumber/features --require-module tsx/cjs --require tests/cucumber/steps/index.js

integration:
node_modules/.bin/cucumber-js --tags $(INTEGRATIONS_TAGS) tests/cucumber/features --require-module ts-node/register --require tests/cucumber/steps/index.js
node_modules/.bin/cucumber-js --tags $(INTEGRATIONS_TAGS) tests/cucumber/features --require-module tsx/cjs --require tests/cucumber/steps/index.js

# The following assumes that all cucumber steps are defined in `./tests/cucumber/steps/steps.js` and begin past line 135 of that file.
# Please note any deviations of the above before presuming correctness.
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

AlgoSDK is the official JavaScript library for communicating with the Algorand network. It's designed for modern browsers and Node.js.

## New Major Version 3

Existing codebases using v2 of this library will be incompatible with v3. The v3 release introduces breaking changes to the API, and a migration guide is available [here](v2_TO_v3_MIGRATION_GUIDE.md).

## Installation

### [Node.js](https://nodejs.org/en/download/)
Expand All @@ -20,8 +24,8 @@ Include a minified browser bundle directly in your HTML like so:

```html
<script
src="https://unpkg.com/algosdk@v2.9.0/dist/browser/algosdk.min.js"
integrity="sha384-R84o0hH3cBFIzv9uqyKcDNfDi/6jgn1MrS1/tOMDWxeh8hWfOLuRoMy0LekUm2KL"
src="https://unpkg.com/algosdk@v3.0.0-beta.1/dist/browser/algosdk.min.js"
integrity="sha384-t7Y1U/AQgArvpZIYSrQgV1OqfMPWzq42ev7TLh5sl5hVRYsi1K3CehK4rYR5UYmE"
crossorigin="anonymous"
></script>
```
Expand All @@ -30,8 +34,8 @@ or

```html
<script
src="https://cdn.jsdelivr.net/npm/algosdk@v2.9.0/dist/browser/algosdk.min.js"
integrity="sha384-R84o0hH3cBFIzv9uqyKcDNfDi/6jgn1MrS1/tOMDWxeh8hWfOLuRoMy0LekUm2KL"
src="https://cdn.jsdelivr.net/npm/algosdk@v3.0.0-beta.1/dist/browser/algosdk.min.js"
integrity="sha384-t7Y1U/AQgArvpZIYSrQgV1OqfMPWzq42ev7TLh5sl5hVRYsi1K3CehK4rYR5UYmE"
crossorigin="anonymous"
></script>
```
Expand Down
1 change: 1 addition & 0 deletions dist/esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "module"}
38 changes: 21 additions & 17 deletions examples/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function main() {
const mnemonic =
'creek phrase island true then hope employ veteran rapid hurdle above liberty tissue connect alcohol timber idle ten frog bulb embody crunch taxi abstract month';
const recoveredAccount = algosdk.mnemonicToSecretKey(mnemonic);
console.log('Recovered mnemonic account: ', recoveredAccount.addr);
console.log('Recovered mnemonic account: ', recoveredAccount.addr.toString());
// example: ACCOUNT_RECOVER_MNEMONIC

const funder = accounts[0];
Expand All @@ -31,30 +31,30 @@ async function main() {
signerAccounts.push(algosdk.generateAccount());

// multiSigParams is used when creating the address and when signing transactions
const multiSigParams = {
const multiSigParams: algosdk.MultisigMetadata = {
version: 1,
threshold: 2,
addrs: signerAccounts.map((a) => a.addr),
};
const multisigAddr = algosdk.multisigAddress(multiSigParams);

console.log('Created MultiSig Address: ', multisigAddr);
console.log('Created MultiSig Address: ', multisigAddr.toString());
// example: MULTISIG_CREATE

const fundMsigTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: funder.addr,
to: multisigAddr,
sender: funder.addr,
receiver: multisigAddr,
amount: 1_000_000,
suggestedParams,
});

await client.sendRawTransaction(fundMsigTxn.signTxn(funder.privateKey)).do();
await algosdk.waitForConfirmation(client, fundMsigTxn.txID().toString(), 3);
await algosdk.waitForConfirmation(client, fundMsigTxn.txID(), 3);

// example: MULTISIG_SIGN
const msigTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: multisigAddr,
to: funder.addr,
sender: multisigAddr,
receiver: funder.addr,
amount: 100,
suggestedParams,
});
Expand All @@ -74,46 +74,50 @@ async function main() {
).blob;

await client.sendRawTransaction(msigWithSecondSig).do();
await algosdk.waitForConfirmation(client, msigTxn.txID().toString(), 3);
await algosdk.waitForConfirmation(client, msigTxn.txID(), 3);
// example: MULTISIG_SIGN

// example: ACCOUNT_GENERATE
const generatedAccount = algosdk.generateAccount();
const passphrase = algosdk.secretKeyToMnemonic(generatedAccount.sk);
console.log(`My address: ${generatedAccount.addr}`);
console.log(`My address: ${generatedAccount.addr.toString()}`);
console.log(`My passphrase: ${passphrase}`);
// example: ACCOUNT_GENERATE

// example: ACCOUNT_REKEY
// rekey the original account to the new signer via a payment transaction
// Note any transaction type can be used to rekey an account
const rekeyTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: acct1.addr,
to: acct1.addr,
sender: acct1.addr,
receiver: acct1.addr,
amount: 0,
suggestedParams,
rekeyTo: acct2.addr, // set the rekeyTo field to the new signer
});

await client.sendRawTransaction(rekeyTxn.signTxn(acct1.privateKey)).do();
await algosdk.waitForConfirmation(client, rekeyTxn.txID().toString(), 3);
await algosdk.waitForConfirmation(client, rekeyTxn.txID(), 3);

const acctInfo = await client.accountInformation(acct1.addr).do();

console.log(`Account Info: ${acctInfo} Auth Addr: ${acctInfo['auth-addr']}`);
console.log(
`Account Info: ${algosdk.stringifyJSON(acctInfo)} Auth Addr: ${
acctInfo['auth-addr']
}`
);
// example: ACCOUNT_REKEY

// the transaction is from originalAccount, but signed with newSigner private key

const rekeyBack = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: acct1.addr,
to: acct1.addr,
sender: acct1.addr,
receiver: acct1.addr,
amount: 0,
suggestedParams,
rekeyTo: acct1.addr,
});
await client.sendRawTransaction(rekeyBack.signTxn(acct2.privateKey)).do();
await algosdk.waitForConfirmation(client, rekeyBack.txID().toString(), 3);
await algosdk.waitForConfirmation(client, rekeyBack.txID(), 3);
}

main();
Loading