-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(crypto): remove circular dependency
- Loading branch information
1 parent
842e183
commit 9917a4f
Showing
4 changed files
with
48 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as uint8arrays from 'uint8arrays' | ||
import { | ||
BASE58_MULTIBASE_PREFIX, | ||
DID_KEY_PREFIX | ||
} from './const' | ||
|
||
export const extractMultikey = (did: string): string => { | ||
if (!did.startsWith(DID_KEY_PREFIX)) { | ||
throw new Error(`Incorrect prefix for did:key: ${did}`) | ||
} | ||
return did.slice(DID_KEY_PREFIX.length) | ||
} | ||
|
||
export const extractPrefixedBytes = (multikey: string): Uint8Array => { | ||
if (!multikey.startsWith(BASE58_MULTIBASE_PREFIX)) { | ||
throw new Error(`Incorrect prefix for multikey: ${multikey}`) | ||
} | ||
return uint8arrays.fromString( | ||
multikey.slice(BASE58_MULTIBASE_PREFIX.length), | ||
'base58btc', | ||
) | ||
} | ||
|
||
export const hasPrefix = (bytes: Uint8Array, prefix: Uint8Array): boolean => { | ||
return uint8arrays.equals(prefix, bytes.subarray(0, prefix.byteLength)) | ||
} |