-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(admin-api): enable auth headers for admin api routes #354
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ca4ff7b
feat: initial update for node ui auth
frdomovic 12518d1
feat: add headers checks
frdomovic e1a73ab
fix: remove unused imports
frdomovic 1eaf50a
fix: remove get did function
frdomovic e612e44
feat: add auth layer to admin api
frdomovic 169fc67
fix: remove client key route from protected routes
frdomovic 174cd1c
feat: initial sdk auth headers update
frdomovic 70cdce1
fix: remove auth for public routes
frdomovic 056c747
fix: remove auth headers from login
frdomovic 4052a46
feat: bump sdk version
frdomovic 3acb815
fix: revert file
frdomovic c4194d8
fix: space fix
frdomovic 76330b9
fix: replace headers map with axios header
frdomovic 5007e49
fix: bump sdk version
frdomovic 596fe75
Merge branch 'master' into C20-87_add_admin_ui_auth
frdomovic 9109673
fix: rename unprotected router
frdomovic 91a3402
fix: add root key to protected routes
frdomovic 0fb0a4a
fix: requested changes
frdomovic 7777f00
fix: lint
frdomovic af0a7e1
fix: typo
frdomovic c917e31
fix: variable camel case
frdomovic 06edebd
fix: rename axios header to header
frdomovic 0efeb1d
fix: remove default context id value
frdomovic 61d56a3
Merge branch 'master' into C20-87_add_admin_ui_auth
frdomovic 777dd20
fix: remove clone
frdomovic dfef99e
Merge branch 'master' into C20-87_add_admin_ui_auth
frdomovic 579f480
feat: bump sdk version to 0.0.23
frdomovic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { unmarshalPrivateKey } from '@libp2p/crypto/keys'; | ||
import { PrivateKey } from '@libp2p/interface'; | ||
import bs58 from 'bs58'; | ||
import { WalletType } from '../api/nodeApi'; | ||
import { ClientKey } from '../types/storage'; | ||
import { getStorageClientKey } from '../storage/storage'; | ||
|
||
export interface Header { | ||
[key: string]: string; | ||
} | ||
|
||
export async function createAuthHeader( | ||
payload: string, | ||
contextId: string | ||
): Promise<Header | null> { | ||
const privateKey: PrivateKey = await getPrivateKey(); | ||
|
||
if (!privateKey) { | ||
return null; | ||
} | ||
|
||
const encoder = new TextEncoder(); | ||
const contentBuff = encoder.encode(payload); | ||
|
||
const signingKey = bs58.encode(privateKey.public.bytes); | ||
|
||
const hashBuffer = await crypto.subtle.digest('SHA-256', contentBuff); | ||
const hashArray = new Uint8Array(hashBuffer); | ||
|
||
const signature = await privateKey.sign(hashArray); | ||
const signatureBase58 = bs58.encode(signature); | ||
const contentBase58 = bs58.encode(hashArray); | ||
|
||
const headers: Header = { | ||
wallet_type: JSON.stringify(WalletType.NEAR), | ||
signing_key: signingKey, | ||
signature: signatureBase58, | ||
challenge: contentBase58, | ||
context_id: contextId, | ||
}; | ||
|
||
return headers; | ||
} | ||
|
||
export async function getPrivateKey(): Promise<PrivateKey | null> { | ||
try { | ||
const clientKey: ClientKey | null = getStorageClientKey(); | ||
if (!clientKey) { | ||
return null; | ||
} | ||
return await unmarshalPrivateKey(bs58.decode(clientKey.privateKey)); | ||
} catch (error) { | ||
console.error('Error extracting private key:', error); | ||
return null; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './headers'; | ||
export * from './ed25519'; |
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
2 changes: 1 addition & 1 deletion
2
packages/calimero-sdk/src/wallets/MetamaskLogin/LoginWithMetamask.tsx
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if this will work across multiple calls. We had some issues with cloning store before but can't recall exactly what was it