septs
2021-01-30
see Allow add external algorithm bridge · Issue #248 · w3c/webcrypto · GitHub
class Ed25519SubtleBridge extends CryptoSubtleBridge {
constructor() {
Object.freeze(this)
}
sign(/* ... */) { /* ... */ }
verify(/* ... */) { /* ... */ }
deriveKey(/* ... */) { /* ... */ }
deriveBits(/* ... */) { /* ... */ }
generateKey(/* ... */) { /* ... */ }
importKey(/* ... */) { /* ... */ }
exportKey(/* ... */) { /* ... */ }
get [Symbol.toStringTag]() {
return '@Ed25519' // e.g: external algorithm name need fixed prefix, `@`
}
}
crypto.addSubtleBridge(Ed25519SubtleBridge)
class SHA3SubtleBridge extends CryptoSubtleBridge {
constructor() {
Object.freeze(this)
}
digest(algorithm/*: string */, data/*: BufferSource */) {/* ... */}
get [Symbol.toStringTag]() {
return '@SHA-3'
}
}
crypto.addSubtleBridge(SHA3SubtleBridge)
Motive:
- allow polyfill non-standard algorithm use unified interface on crypto operation
- make different libraries have the same api style
- unified web-side and nodejs-side* use same code
* nodejs 15 starts provide Web Crypto API | Node.js v15.7.0 Documentation implementation