-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
176 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"fuels": patch | ||
"@fuel-ts/keystore": patch | ||
--- | ||
|
||
Fixing ESM support for NodeJS, using individual builds for Browser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { encrypt, decrypt } from "fuels"; | ||
|
||
/** | ||
* Will throw if ESM support for NodeJS is broken: | ||
* - https://github.com/FuelLabs/fuels-ts/issues/909 | ||
*/ | ||
export { encrypt, decrypt }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"private": true, | ||
"name": "demo-node-esm", | ||
"description": "Simple NodeJS demo using ESM modules", | ||
"author": "Fuel Labs <[email protected]> (https://fuel.network/)", | ||
"type": "module", | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"build": "pnpm test", | ||
"test": "node ./index.mjs" | ||
}, | ||
"dependencies": { | ||
"fuels": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
describe.skip('Keystore', () => { | ||
// TODO: mimick tests from `../node/aes-ctr.ts` | ||
/** | ||
* Testing the web version for this implementation requires us to run | ||
* this test inside the browser, which we currently do not do, and, | ||
* because of this, this file is just a stub-reminder of what needs | ||
* to be done when we get there. | ||
* | ||
* The necessary tests should be similar or identical the ones we | ||
* have on `../node/aes-ctr.ts`, but that can only be confirmed | ||
* when we get to this point. | ||
*/ | ||
test('Encrypt and Decrypt', () => { | ||
expect(true).toBeTruthy; | ||
}); | ||
}); |
41 changes: 38 additions & 3 deletions
41
packages/keystore/src/aes-ctr-web.ts → packages/keystore/src/browser/aes-ctr.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { crypto, btoa } = globalThis; | ||
|
||
if (!crypto) { | ||
throw new Error(`Could not found 'crypto' in current browser environment`); | ||
} | ||
|
||
if (!btoa) { | ||
throw new Error(`Could not found 'btoa' in current browser environment`); | ||
} | ||
|
||
export { crypto, btoa }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { crypto } from './crypto'; | ||
|
||
export const randomBytes = (length: number) => { | ||
const randomValues = crypto.getRandomValues(new Uint8Array(length)); | ||
return randomValues; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './browser/aes-ctr'; | ||
export * from './browser/randomBytes'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './keystore'; | ||
export * from './node/aes-ctr'; | ||
export * from './node/randomBytes'; | ||
export * from './types'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 30 additions & 3 deletions
33
packages/keystore/src/aes-ctr-node.ts → packages/keystore/src/node/aes-ctr.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import crypto from 'crypto'; | ||
|
||
export const randomBytes = (length: number) => { | ||
const randomValues = crypto.randomBytes(length); | ||
return randomValues; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface Keystore { | ||
data: string; | ||
iv: string; | ||
salt: string; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
import { index } from '@internal/tsup'; | ||
import type { Options } from 'tsup'; | ||
|
||
export default index; | ||
export const keystoreOptions: Options[] = [ | ||
{ | ||
...index, | ||
entry: ['src/index.ts'], | ||
format: ['cjs'], | ||
}, | ||
{ | ||
...index, | ||
entry: ['src/index.ts', 'src/index.browser.ts'], | ||
format: ['esm'], | ||
}, | ||
]; | ||
|
||
export default keystoreOptions; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.