Coder Social home page Coder Social logo

wallets's Introduction

MyCrypto Wallets

WORK IN PROGRESS

Wallet abstractions to be used throughout the MyCrypto product suite.

wallets's People

Contributors

frederikbolding avatar mrtenz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wallets's Issues

async function should have await expression JS-0116

DESCRIPTION

A function that does not contain any await expressions should not be async (except for some edge cases in TypeScript which are discussed below). Asynchronous functions in JavaScript behave differently than other functions in two important ways:

The return value is always a Promise.
You can use the await operator inside them.
Functions are made async so that we can use the await operator inside them. Consider this example:

async function fetchData(processDataItem) {
const response = await fetch(DATA_URL);
const data = await response.json();

return data.map(processDataItem);

}
Asynchronous functions that don't use await might be an unintentional result of refactoring.

Note: This issue ignores async generator functions. Generators yield rather than return a value and async generators might yield all the values of another async generator without ever actually needing to use await.

In TypeScript, one might feel the need to make a function async to comply with type signatures defined by an interface. Ideally, the code should be refactored to get rid of such restrictions, but sometimes that isn't feasible (For example, when we are implementing an interface defined in a 3rd party library like Next.js).

This situation can easily be circumvented by returning the value with a call to Promise.resolve:

interface HasAsyncFunc {
getNum: () => Promise
}

// Not recommended:
const o: HasAsyncFunc = {
async getNum() { return 1 }
}

// Recommended:
const o: HasAsyncFunc = {
// We only use Promise.resolve to adhere to the type
// of the surrounding object.
getNum() { return Promise.resolve(1) }
}
It is also advised to add a comment near the redundant promise to make the intent clear.

BAD PRACTICE
async function fetchData(): string {
// readFileSync is a synchronous function that blocks
// the main thread, and thus does not need to be awaited
return fs.readFileSync("data.txt", "utf-8");
}

performAction(async () => { console.log("no awaits in here") });
RECOMMENDED
async function fetchDataAsync(): Promise {
return await fs.readFile("data.txt", "utf-8")
}

performAction(async () => { await writeToFile(data) });

// Allow empty functions.
async function no_op() {}

Look here to fix it:

Found async function without any await expressions
src/deterministic-wallet.ts

return node.neuter().extendedKey;

}

async getAddressesWithMultipleDPaths(
input: {
path: DerivationPath;
limit: number;
offset?: number;
}[]
): Promise<DeterministicAddress[]> {
const promises = input.map(({ path, limit, offset }) => () =>
this.getAddresses({ path, limit, offset })
);
return sequence(promises).then((results) => results.flat());
}

async getAddresses({
path,
Found async function without any await expressions
src/implementations/deterministic/gridplus.test.ts

});

describe('getCredentials', () => {
it('returns credentials', async () => {
const wallet = new GridPlusWallet(config);
expect(wallet.getCredentials()).toStrictEqual({
deviceID: config.deviceID,
password: config.password
});
});
});
});
Found async function without any await expressions
src/implementations/deterministic/gridplus.ts

return this.address;

}

async getPrivateKey(): Promise {
throw new Error('Method not implemented.');
}
}

export class GridPlusWallet extends HardwareWallet {
Found async function without any await expressions
src/implementations/deterministic/gridplus.ts

return wallet.getAddress();

}

async getExtendedKey(_path: string): Promise<{ publicKey: string; chainCode: string }> {
throw new Error('Method not implemented.');
}

async getHardenedAddress(path: DerivationPath, index: number): Promise {
return this.getAddress(path, index);
Found async function without any await expressions
src/implementations/deterministic/gridplus.ts

throw new Error('Method not implemented.');

}

async getHardenedAddress(path: DerivationPath, index: number): Promise {
return this.getAddress(path, index);
}

// Manually scan for addresses since extended key information is not available currently
async getAddresses({Found async function without any await expressions
src/deterministic-wallet.ts

return node.neuter().extendedKey;

}

async getAddressesWithMultipleDPaths(
input: {
path: DerivationPath;
limit: number;
offset?: number;
}[]
): Promise<DeterministicAddress[]> {
const promises = input.map(({ path, limit, offset }) => () =>
this.getAddresses({ path, limit, offset })
);
return sequence(promises).then((results) => results.flat());
}

async getAddresses({
path,
Found async function without any await expressions
src/implementations/deterministic/gridplus.test.ts

});

describe('getCredentials', () => {
it('returns credentials', async () => {
const wallet = new GridPlusWallet(config);
expect(wallet.getCredentials()).toStrictEqual({
deviceID: config.deviceID,
password: config.password
});
});
});
});
Found async function without any await expressions
src/implementations/deterministic/gridplus.ts

return this.address;

}

async getPrivateKey(): Promise {
throw new Error('Method not implemented.');
}
}

export class GridPlusWallet extends HardwareWallet {
Found async function without any await expressions
src/implementations/deterministic/gridplus.ts

return wallet.getAddress();

}

async getExtendedKey(_path: string): Promise<{ publicKey: string; chainCode: string }> {
throw new Error('Method not implemented.');
}

async getHardenedAddress(path: DerivationPath, index: number): Promise {
return this.getAddress(path, index);
Found async function without any await expressions
src/implementations/deterministic/gridplus.ts

throw new Error('Method not implemented.');

}

async getHardenedAddress(path: DerivationPath, index: number): Promise {
return this.getAddress(path, index);
}

// Manually scan for addresses since extended key information is not available currently
async getAddresses({

Invalid async/await call

DESCRIPTION

Detected awaiting a value that is not a "Thenable" (an object which has a then method, such as a Promise).

While it is valid JavaScript to await a non-Promise-like value (it will resolve immediately), this pattern is often a programmer error, such as forgetting to add parenthesis to call a function that returns a Promise.

BAD PRACTICE

await 'value';

const createValue = () => 'value';
await createValue();

RECOMMENDED

await Promise.resolve('value');

const createValue = async () => 'value';
await createValue();

Look here: Unexpected await of a non-Promise (non-"Thenable") value
src/implementations/deterministic/mnemonic-phrase.spec.ts

});

it('creates mnemonic correctly', async () => {
const mnemonic = await MnemonicPhrase.create();
return expect(mnemonic.mnemonicPhrase).toEqual(fMnemonicPhrase);
});

Give star and donate for my work :)

Bulk vulnerability fix - Lockfile fix #1

Fixed vulnerabilities:
CVE–2021–23364 debricked

CVE–2021–23343 debricked

CVE–2021–32640 debricked

CVE–2020–28469 debricked

CVE–2021–3777 debricked

CVE–2021–3918 debricked

CVE–2022–0155 debricked

CVE–2022–0355 debricked

CVE–2022–0536 debricked

CVE–2022–37599 debricked

CVE–2022–37601 debricked

CVE–2022–37603 debricked

CVE–2022–3517 debricked

CVE–2022–24999 debricked

CVE–2022–38900 debricked

CVE–2022–46175 debricked

CVE–2022–25901 debricked

CVE–2022–38778 debricked

CVE–2023–28155 debricked

CVE–2022–25883 debricked

CVE–2023–26115 debricked

philipjonsen#1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.