-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve cargo feature handling and crypto APIs definition
This commit improves the `crypto` feature handling by making the relationship between crypto and the experimental_event_loop explicit. If `crypto` is defined, the `experimental_event_loop` feature will also be enbabled. Additionally, this commit makes it easier to define the async crypto APIs by introducing a `crypto.js` file that defines JS bits to make it easier to return a promise.
- Loading branch information
1 parent
247e59c
commit fa3c661
Showing
11 changed files
with
89 additions
and
73 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
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
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
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,17 @@ | ||
(function() { | ||
const __javy_cryptoSubtleSign = globalThis.__javy_cryptoSubtleSign; | ||
|
||
const crypto = { | ||
subtle: {} | ||
}; | ||
|
||
|
||
crypto.subtle.sign = function(obj, key, msg) { | ||
return new Promise((resolve, _) => { | ||
resolve(__javy_cryptoSubtleSign(obj, key, msg)); | ||
}); | ||
} | ||
|
||
globalThis.crypto = crypto; | ||
Reflect.deleteProperty(globalThis, "__javy_cryptoSubtleSign"); | ||
})(); |
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
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
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,9 +1,11 @@ | ||
const promiseA = new Promise((resolve, reject) => { | ||
resolve(777); | ||
}); | ||
// At this point, "promiseA" is already settled. | ||
async f () => { | ||
await promiseA.then((val) => console.log("asynchronous logging has val:", val)); | ||
|
||
export async function main() { | ||
const expectedHex = "97d2a569059bbcd8ead4444ff99071f4c01d005bcefe0d3567e1be628e5fdcd9"; | ||
|
||
const result = await crypto.subtle.sign({name: "HMAC", hash: "sha-256"}, "my secret and secure key", "input message"); | ||
console.log(result); | ||
console.log(result === expectedHex); | ||
} | ||
f(); | ||
console.log("immediate logging"); | ||
|
||
await main(); | ||
|