Skip to content

Commit

Permalink
Merge pull request #7 from kentbull/align-api-with-docs
Browse files Browse the repository at this point in the history
refactor: change saidify args order to put label 2nd
  • Loading branch information
kentbull authored Aug 18, 2024
2 parents 8fa13a7 + 3b477b4 commit 2482a31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
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

0 comments on commit 2482a31

Please sign in to comment.