-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial support jwt signing on ledger
- Loading branch information
1 parent
c6c8c52
commit 5f4696e
Showing
51 changed files
with
689 additions
and
869 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,35 @@ | ||
import { makeDIDFromAddress } from '@stacks/auth'; | ||
import { makeUUID4, nextMonth } from '@stacks/common'; | ||
import { publicKeyToAddress } from '@stacks/encryption'; | ||
import { createUnsecuredToken } from 'jsontokens'; | ||
import base64url from 'base64url'; | ||
|
||
export async function makeUnsafeAuthResponse( | ||
publicKey: string, | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
profile: {} = {}, | ||
username: string | null = null, | ||
_metadata: any | null, | ||
coreToken: string | null = null, | ||
_appPrivateKey: string | null = null, | ||
expiresAt: number = nextMonth().getTime(), | ||
_transitPublicKey: string | null = null, | ||
_hubUrl: string | null = null, | ||
_blockstackAPIUrl: string | null = null, | ||
_associationToken: string | null = null | ||
): Promise<string> { | ||
const address = publicKeyToAddress(publicKey); | ||
export async function makeLedgerCompatibleUnsignedAuthResponsePayload({ | ||
dataPublicKey, | ||
profile = {}, | ||
expiresAt = nextMonth().getTime(), | ||
}: { | ||
dataPublicKey: string; | ||
profile: any; | ||
expiresAt?: number; | ||
}): Promise<string> { | ||
const address = publicKeyToAddress(dataPublicKey); | ||
|
||
// /* See if we should encrypt with the transit key */ | ||
// let privateKeyPayload = appPrivateKey; | ||
const coreTokenPayload = coreToken; | ||
const additionalProperties = {}; | ||
// if (appPrivateKey !== undefined && appPrivateKey !== null) { | ||
// // Logger.info(`blockstack.js: generating v${VERSION} auth response`) | ||
// if (transitPublicKey !== undefined && transitPublicKey !== null) { | ||
// privateKeyPayload = await encryptPrivateKey(transitPublicKey, appPrivateKey); | ||
// if (coreToken !== undefined && coreToken !== null) { | ||
// coreTokenPayload = await encryptPrivateKey(transitPublicKey, coreToken); | ||
// } | ||
// } | ||
// additionalProperties = { | ||
// email: metadata?.email ? metadata.email : null, | ||
// profile_url: metadata?.profileUrl ? metadata.profileUrl : null, | ||
// hubUrl, | ||
// blockstackAPIUrl, | ||
// associationToken, | ||
// version: VERSION, | ||
// }; | ||
// } else { | ||
// // Logger.info('blockstack.js: generating legacy auth response') | ||
// } | ||
const payload = { | ||
jti: makeUUID4(), | ||
iat: Math.floor(new Date().getTime() / 1000), // JWT times are in seconds | ||
exp: Math.floor(expiresAt / 1000), // JWT times are in seconds | ||
iss: makeDIDFromAddress(address), | ||
public_keys: [dataPublicKey], | ||
profile, | ||
}; | ||
|
||
/* Create the payload */ | ||
const payload = Object.assign( | ||
{}, | ||
{ | ||
jti: makeUUID4(), | ||
iat: Math.floor(new Date().getTime() / 1000), // JWT times are in seconds | ||
exp: Math.floor(expiresAt / 1000), // JWT times are in seconds | ||
iss: makeDIDFromAddress(address), | ||
// private_key: privateKeyPayload, | ||
public_keys: [publicKey], | ||
profile, | ||
username, | ||
core_token: coreTokenPayload, | ||
}, | ||
additionalProperties | ||
); | ||
const header = { typ: 'JWT', alg: 'ES256K' }; | ||
|
||
return createUnsecuredToken(payload); | ||
const formedHeader = base64url.encode(JSON.stringify(header)); | ||
|
||
const formedPayload = base64url.encode(JSON.stringify(payload)); | ||
|
||
const inputToSign = [formedHeader, formedPayload].join('.'); | ||
|
||
return inputToSign; | ||
} |
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,7 +1,12 @@ | ||
import { isValidUrl } from '@app/common/validation/validate-url'; | ||
import { RouteUrls } from '@shared/route-urls'; | ||
|
||
export const openInNewTab = (url: string) => { | ||
export function openInNewTab(url: string) { | ||
if (!isValidUrl(url)) return; | ||
const newWindow = window.open(url, '_blank', 'noopener,noreferrer'); | ||
if (newWindow) newWindow.opener = null; | ||
}; | ||
} | ||
|
||
export function openIndexPageInNewTab(path: RouteUrls | string) { | ||
return chrome.tabs.create({ url: chrome.runtime.getURL('index.html#' + path) }); | ||
} |
Oops, something went wrong.