-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: handle multiple unlock types in
getInputsPreExpandedConfig
(
#1113) * refactor: handle multiple unlock types in getInputsPreExpandedConfig * feat: handle transitive unlocks * refactor: create util `resolveTransitiveUnlock` --------- Co-authored-by: Mario <[email protected]>
- Loading branch information
Showing
3 changed files
with
31 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ReferenceUnlock, SignatureUnlock, Unlock, UnlockType } from "@iota/sdk-wasm/web"; | ||
|
||
export function resolveTransitiveUnlock(unlocks: Unlock[], unlockIndex: number): SignatureUnlock { | ||
const unlock = unlocks[unlockIndex]; | ||
let signatureUnlock: SignatureUnlock; | ||
if (unlock.type === UnlockType.Signature) { | ||
signatureUnlock = unlock as SignatureUnlock; | ||
} else { | ||
let refUnlockIdx = unlockIndex; | ||
// unlock references can be transitive, | ||
// so we need to follow the path until we find the signature | ||
do { | ||
const referenceUnlock = unlocks[refUnlockIdx] as ReferenceUnlock; | ||
signatureUnlock = unlocks[referenceUnlock.reference] as SignatureUnlock; | ||
refUnlockIdx = referenceUnlock.reference; | ||
} while (!signatureUnlock.signature); | ||
} | ||
return signatureUnlock; | ||
} |
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