Getting an error in Safari that
alg — ipfs.min.js:42864SyntaxError: Bad algorithm name
Is there anyway to remedy this?
Tracked it down to an algorithm named ECDH in this part of the code:
function alg(a) {
var r = {
name: (a.name || a || "").toUpperCase().replace("V", "v")
};
switch (r.name) {
case "SHA-1":
case "SHA-256":
case "SHA-384":
case "SHA-512":
break;
case "AES-CBC":
case "AES-GCM":
case "AES-KW":
a.length && (r.length = a.length);
break;
case "HMAC":
a.hash && (r.hash = alg(a.hash)), a.length && (r.length = a.length);
break;
case "RSAES-PKCS1-v1_5":
a.publicExponent && (r.publicExponent = new Uint8Array(a.publicExponent)), a.modulusLength && (r.modulusLength = a.modulusLength);
break;
case "RSASSA-PKCS1-v1_5":
case "RSA-OAEP":
a.hash && (r.hash = alg(a.hash)), a.publicExponent && (r.publicExponent = new Uint8Array(a.publicExponent)), a.modulusLength && (r.modulusLength = a.modulusLength);
break;
default:
throw new SyntaxError("Bad algorithm name")
}
return r
}
Thanks for reporting this @lightninglu10. It is a known issue for a while as we focused on developing for Chrome and Firefox (due to their WebRTC support). See compat table here: https://github.com/libp2p/js-libp2p-crypto/issues/18
This means that missing alg need to be shimmed. Is this something you would like to help with?
A major version of Safari (11.0) was released a couple of weeks ago. The WebCrypto API section of the release notes is a little vague and the JS API docs are even less informative, but the release appears to include recent commits to WebKit adding support for the remaining WebCrypto spec ciphers mentioned in https://github.com/libp2p/js-libp2p-crypto/issues/18. See:
https://bugs.webkit.org/show_bug.cgi?id=166746
https://bugs.webkit.org/show_bug.cgi?id=160880
https://trac.webkit.org/browser/webkit/releases/Apple/Safari%2011.0/WebCore/crypto/algorithms
Do we have a volunteer to go and test these new grounds? Thank you for the update, @bertrandrustle
Here's an exhaustive browser test of the WebCrypto API:
https://diafygi.github.io/webcrypto-examples/
Source code:
https://github.com/diafygi/webcrypto-examples/
When Safari is detected the test shims in Safari's soon-to-be-removed crypto.webKitSubtle JS interface. These are the results using Safari 11:

So that interface already seems to support everything IPFS needs. After modifying the test to make Safari use the standard crypto.subtle interface instead, the results with Safari 11 are identical (except now there's no warning in the console about the deprecated crypto.webKitSubtle):

Got ×
Unhandled Rejection (TypeError): Member JsonWebKey.kty is required and must be an instance of DOMString from webcrypto-shim which there is a open issue for (https://github.com/vibornoff/webcrypto-shim/issues/22).
However, there is a merged PR with a working commit though, https://github.com/vibornoff/webcrypto-shim/pull/15/commits/ae3e9fa3ad0cf24748c9025085b4883ba8ed0038 made a PR to our fork that fixes it and now it works 🎉
https://github.com/dignifiedquire/webcrypto-shim/pull/2

PR linked in previous commit has been merged and libp2p-crypto module points to github:dignifiedquire/webcrypto-shim#master so no more changes should be required (just another npm install), js-ipfs should work on Safari 11 now!


Ohh coool thanks @diasdavid !!
Most helpful comment
Safari support is here! 🚀