forked from bluesky-social/atproto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* setting up sql-blockstore * drop table migration * unblock sqlite tx * correct binary types * lol woops * block encoding utilities * no longer store raw record in record table * fix dev-env * pr feedback * tx check
- Loading branch information
Showing
38 changed files
with
307 additions
and
178 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { CID } from 'multiformats/cid' | ||
import * as Block from 'multiformats/block' | ||
import { sha256 as blockHasher } from 'multiformats/hashes/sha2' | ||
import * as blockCodec from '@ipld/dag-cbor' | ||
|
||
export const valueToIpldBlock = async ( | ||
data: unknown, | ||
): Promise<Block.Block<unknown>> => { | ||
return Block.encode({ | ||
value: data, | ||
codec: blockCodec, | ||
hasher: blockHasher, | ||
}) | ||
} | ||
|
||
export const cidForData = async (data: unknown): Promise<CID> => { | ||
const block = await valueToIpldBlock(data) | ||
return block.cid | ||
} | ||
|
||
export const valueToIpldBytes = (value: unknown): Uint8Array => { | ||
return blockCodec.encode(value) | ||
} | ||
|
||
export const ipldBytesToValue = (bytes: Uint8Array) => { | ||
return blockCodec.decode(bytes) | ||
} | ||
|
||
export const ipldBytesToRecord = (bytes: Uint8Array): object => { | ||
const val = ipldBytesToValue(bytes) | ||
if (typeof val !== 'object' || val === null) { | ||
throw new Error(`Expected object, got: ${val}`) | ||
} | ||
return val | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.