diff --git a/lib/toolbox.js b/lib/toolbox.js index 0171ffd9..d1411486 100644 --- a/lib/toolbox.js +++ b/lib/toolbox.js @@ -77,8 +77,23 @@ function derToRaw(signature) { ...extractBigNum(signature, sStart, signature.length, 32), ]); } +function isAndroidFacetId(str) { + return str.startsWith("android:apk-key-hash:"); +} + +function isIOSFacetId(str) { + return str.startsWith("ios:bundle-id:"); +} + function checkOrigin(str) { + if(!str) + throw new Error("Empty Origin"); + + if (isAndroidFacetId(str) || isIOSFacetId(str)) { + return str; + } + const originUrl = new URL(str); const origin = originUrl.origin; diff --git a/test/parseExpectations.test.js b/test/parseExpectations.test.js index 0a8909c1..f621938c 100644 --- a/test/parseExpectations.test.js +++ b/test/parseExpectations.test.js @@ -38,7 +38,7 @@ describe("parseExpectations", function() { assert.strictEqual(ret.get("challenge"), exp.challenge); }); - it("throws on invalid origin", function() { + it("throws on invalid url", function() { const exp = { origin: "asdf", challenge: "4BS1YJKRCeCVoLdfG_b66BuSQ-I2n34WsLFvy62fpIVFjrm32_tFRQixX9U8EBVTriTkreAp-1nDvYboRK9WFg", diff --git a/test/toolbox.test.js b/test/toolbox.test.js index cc9f0608..677fa216 100644 --- a/test/toolbox.test.js +++ b/test/toolbox.test.js @@ -29,10 +29,23 @@ describe("toolbox", function() { checkOrigin(undefined); }, Error, - "Invalid URL", + "Empty Origin", ); }); + + it("accepts android FacetID", function() { + const androidFacetId = "android:apk-key-hash:addf120b430021c36c232c99ef8d926aea2acd6b"; + const androidOrigin = checkOrigin(androidFacetId); + assert.strictEqual(androidFacetId, androidOrigin); + }); + + it("accepts ios FacetID", function() { + const iOSFacetId = "ios:bundle-id:addf120b430021c36c232c99ef8d926aea2acd6b"; + const iOSOrigin = checkOrigin(iOSFacetId); + assert.strictEqual(iOSFacetId, iOSOrigin); + }); + it("throws invalid url", function() { assert.throws( () => {