Skip to content
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

refactor: change saidify args order to put label 2nd #7

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ describe('saidify function tests', () => {
})

it(`produces a valid SAID for Blake3-256 and JSON with data and code arg`, () => {
const saidDataCode = Lib.saidify(data, code)
const saidDataCode = Lib.saidify(data, 'd', code)
expect(saidDataCode).toEqual(`EHSOlNZzwiekacJenXM3qPNU9-07ic_G0ejn8hrA2lKQ`)
})

it(`produces a valid SAID for Blake3-256 and JSON with data and kind arg`, () => {
const saidDataCodeKind = Lib.saidify(data, code, kind)
const saidDataCodeKind = Lib.saidify(data, 'd', code, kind)
expect(saidDataCodeKind).toEqual(`EHSOlNZzwiekacJenXM3qPNU9-07ic_G0ejn8hrA2lKQ`)
})

it(`produces a valid SAID for Blake3-256 and JSON with data, code, kind, and label arg`, () => {
const saidAllArgs = Lib.saidify(data, code, kind, label)
const saidAllArgs = Lib.saidify(data, label, code, kind)
expect(saidAllArgs).toEqual(`EHSOlNZzwiekacJenXM3qPNU9-07ic_G0ejn8hrA2lKQ`)
})
})
Expand All @@ -49,7 +49,7 @@ describe('example code tests', () => {
d: '',
}
const label = 'd'
const said = Lib.saidify(data, SAIDDex.Blake3_256, Serials.JSON, label)
const said = Lib.saidify(data, label, SAIDDex.Blake3_256, Serials.JSON)
expect(said).toEqual('ELLbizIr2FJLHexNkiLZpsTWfhwUmZUicuhmoZ9049Hz')
})
})
Expand Down Expand Up @@ -84,7 +84,7 @@ describe(`verify function tests`, () => {
d: 'ELLbizIr2FJLHexNkiLZpsTWfhwUmZUicuhmoZ9049Hz',
}
const label = 'd'
const doesVerify = Lib.verify(data, said, label, SAIDDex.Blake3_256, Serials.JSON, true)
const doesVerify = Lib.verify(data, said, label)
expect(doesVerify).toEqual(true)
})
})
4 changes: 2 additions & 2 deletions src/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ export function validateRawSize(raw: Uint8Array, code: string = SAIDDex.Blake3_2
* ```
*
* @param data - data to derive self-addressing data from and to add to as a prop labeled by `label`
* @param label - name of the property in the "data" field that will have the SAID placed inside
* @param code - algorithm to be used to derive the SAID
* @param kind - type of serialization to use
* @param label - name of the property in the "data" field that will have the SAID placed inside
*/
export function saidify(
data: Dict<any>,
label: string = 'd',
code: string = SAIDDex.Blake3_256,
kind: Serials = Serials.JSON,
label: string = 'd',
): string {
const [raw, _data] = deriveSAIDBytes(data, code, kind, label)
return qb64(raw, code)
Expand Down
Loading