Skip to content

Instantly share code, notes, and snippets.

@davedoesdev
Last active June 27, 2021 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davedoesdev/1aa0b998fd48acfa4897bd67d459d2dc to your computer and use it in GitHub Desktop.
Save davedoesdev/1aa0b998fd48acfa4897bd67d459d2dc to your computer and use it in GitHub Desktop.
webauthn4js import test
/dist
/node_modules
{
"name": "1aa0b998fd48acfa4897bd67d459d2dc",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"dependencies": {
"typescript": "^4.3.4",
"webauthn4js": "^0.0.12"
}
},
"node_modules/tiny-typed-emitter": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/tiny-typed-emitter/-/tiny-typed-emitter-2.0.3.tgz",
"integrity": "sha512-MaCqhHlp6EAWN25yqBlajgd4scxxI2eJr7+EgoUAOV9UkMU3us/yp2bEnc2yOvyeDF8TUWuaz3zZCPGTKFJIpA=="
},
"node_modules/typescript": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.4.tgz",
"integrity": "sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=4.2.0"
}
},
"node_modules/webauthn4js": {
"version": "0.0.12",
"resolved": "https://registry.npmjs.org/webauthn4js/-/webauthn4js-0.0.12.tgz",
"integrity": "sha512-EyNHnEQNrfvgEdVwETYCiUecLulF41PijvLx8OyzxuKRJyi56DQ9pUIpnYEOB1pwBTX300MbogsbFsdOWdmtPQ==",
"dependencies": {
"tiny-typed-emitter": "^2.0.3"
},
"engines": {
"node": ">= 12"
}
}
},
"dependencies": {
"tiny-typed-emitter": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/tiny-typed-emitter/-/tiny-typed-emitter-2.0.3.tgz",
"integrity": "sha512-MaCqhHlp6EAWN25yqBlajgd4scxxI2eJr7+EgoUAOV9UkMU3us/yp2bEnc2yOvyeDF8TUWuaz3zZCPGTKFJIpA=="
},
"typescript": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.4.tgz",
"integrity": "sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew=="
},
"webauthn4js": {
"version": "0.0.12",
"resolved": "https://registry.npmjs.org/webauthn4js/-/webauthn4js-0.0.12.tgz",
"integrity": "sha512-EyNHnEQNrfvgEdVwETYCiUecLulF41PijvLx8OyzxuKRJyi56DQ9pUIpnYEOB1pwBTX300MbogsbFsdOWdmtPQ==",
"requires": {
"tiny-typed-emitter": "^2.0.3"
}
}
}
}
{
"dependencies": {
"typescript": "^4.3.4",
"webauthn4js": "^0.0.12"
}
}
#!/bin/bash
set -e
npm install
rm -rf dist
./node_modules/.bin/tsc
node dist/test.js
import makeWebAuthn, { WebAuthn4JS } from 'webauthn4js';
async function initWebAuthn(clientId: string): Promise<{ webauthn: WebAuthn4JS }> {
const appData = {
displayName: 'test',
id: 'test',
origin: 'http://test:80',
icon: 'http://test/test.gif'
}
const webauthn = await makeWebAuthn({
RPDisplayName: appData.displayName,
RPID: appData.id,
RPOrigin: appData.origin.toLowerCase(),
RPIcon: appData.icon,
AuthenticatorSelection: {
userVerification: 'preferred',
},
Timeout: 60000,
});
return { webauthn };
}
async function register(clientId: string) {
const { webauthn } = await initWebAuthn(clientId);
const user = {
id: 'test',
name: 'test',
displayName: 'test',
iconURL: 'http://test/test.gif',
credentials: []
};
const excludeCreds = [];
const challenge = "";
// create user info and challenge here
const { options, sessionData } = await webauthn.beginRegistration(user, cco => {
cco.excludeCredentials = excludeCreds;
cco.challenge = challenge;
return cco;
});
return { options, sessionData }
}
(async function () {
console.log(await register('foobar'));
})();
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"allowSyntheticDefaultImports": false,
"moduleResolution": "node",
"esModuleInterop": true
},
"exclude": ["node_modules", "dist"],
"files": [
"test.ts"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment