-
Notifications
You must be signed in to change notification settings - Fork 0
Token generation: KV tokens #60
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,6 +43,20 @@ const MAX_EVENTS_AFTER = Number.parseInt(process.env.MAX_EVENTS_AFTER || '', 10) | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| const copiedExistingData = Symbol('copiedExistingData') | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export const findAllKeyIdsByName = ( | ||||||||||||||||||||||
| state: ChelContractState, | ||||||||||||||||||||||
| name: string | ||||||||||||||||||||||
| ): string[] | null | undefined => | ||||||||||||||||||||||
| state._vm?.authorizedKeys && | ||||||||||||||||||||||
| Object.values(state._vm.authorizedKeys) | ||||||||||||||||||||||
| .filter((k) => k.name === name) | ||||||||||||||||||||||
| .sort((a, b) => { | ||||||||||||||||||||||
| if (a._notAfterHeight == null) return 1 | ||||||||||||||||||||||
| if (b._notAfterHeight == null) return 1 | ||||||||||||||||||||||
| return a._notAfterHeight - b._notAfterHeight | ||||||||||||||||||||||
|
Comment on lines
+53
to
+56
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 The sort comparator at
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||||||
| }) | ||||||||||||||||||||||
| .map(k => k.id) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export const findKeyIdByName = ( | ||||||||||||||||||||||
| state: ChelContractState, | ||||||||||||||||||||||
| name: string | ||||||||||||||||||||||
|
|
@@ -1248,3 +1262,34 @@ export const updateKey = (key: ChelContractKey, updatedKey: ChelContractKey): Ch | |||||||||||||||||||||
| ...(updatedKey.meta ? { meta: updatedKey.meta } : {}) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| export const freshDeletionToken = ( | ||||||||||||||||||||||
| state: ChelContractState, signingKeyName: string, objectCid: string, kvKey?: string | ||||||||||||||||||||||
| ): { token: string, hint: string } | undefined => { | ||||||||||||||||||||||
| const signingKeyId = findKeyIdByName(state, signingKeyName) | ||||||||||||||||||||||
| if (!signingKeyId) return | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const tokenData = `deletionToken/${objectCid}${kvKey ? `/${kvKey}` : ''}` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const key = (sbp('chelonia/rootState') as ChelRootState).secretKeys[signingKeyId] | ||||||||||||||||||||||
| const token = sign(key, tokenData).slice(0, 24) | ||||||||||||||||||||||
|
Comment on lines
+1273
to
+1274
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 In both Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||||||
| const hint = findAllKeyIdsByName(state, signingKeyName)?.findIndex((id) => id === signingKeyId) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return { | ||||||||||||||||||||||
| token, | ||||||||||||||||||||||
| hint: String(hint) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export const deletionTokenFromHint = ( | ||||||||||||||||||||||
| state: ChelContractState, signingKeyName: string, hint: string, objectCid: string, kvKey?: string | ||||||||||||||||||||||
| ): string | undefined => { | ||||||||||||||||||||||
| const signingKeyId = findAllKeyIdsByName(state, signingKeyName)?.[Number(hint)] | ||||||||||||||||||||||
| if (!signingKeyId) return | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const tokenData = `deletionToken/${objectCid}${kvKey ? `/${kvKey}` : ''}` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const key = (sbp('chelonia/rootState') as ChelRootState).secretKeys[signingKeyId] | ||||||||||||||||||||||
| const token = sign(key, tokenData).slice(0, 24) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return token | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
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.
🔴
deletionTokenFromHintcalled with wrong argument order —uploader.hintis never passedThe call at
src/chelonia.ts:2422passes(state, uploader.keyName, contractID, key), but the function signature atsrc/utils.ts:1283-1284is(state, signingKeyName, hint, objectCid, kvKey?). This meanscontractIDis passed as thehintparameter (should beuploader.hint),key(the KV key) is passed asobjectCid(should becontractID), and the actual KV key is never passed askvKey. Theuploader.hintvalue, which is the whole reason this branch exists (uploader.hint != null), is completely ignored, so the wrong key will be looked up and the wrong deletion token will be generated.Was this helpful? React with 👍 or 👎 to provide feedback.