diff --git a/src/keri/app/credentialing.ts b/src/keri/app/credentialing.ts index 44d14131..ee74415b 100644 --- a/src/keri/app/credentialing.ts +++ b/src/keri/app/credentialing.ts @@ -17,8 +17,6 @@ import { Serder } from '../core/serder'; import { Siger } from '../core/siger'; import { TextDecoder } from 'util'; import { TraitDex } from './habery'; -import { Prefixer } from '../core/prefixer'; -import { Seqner } from '../core/seqner'; import { serializeACDCAttachment, serializeIssExnAttachment, @@ -776,9 +774,7 @@ export class Ipex { i: recp, }; - let prefixer = new Prefixer({ raw: b(acdc.raw) }); - let seqner = new Seqner({ sn: acdc.sn }); - let acdcAtc = d(serializeACDCAttachment(prefixer, seqner, acdcSaider)); + let acdcAtc = d(serializeACDCAttachment(acdc, acdcSaider)); let issAtc = d(serializeIssExnAttachment(anc, issSaider)); let embeds: any = { diff --git a/src/keri/core/utils.ts b/src/keri/core/utils.ts index 76952896..07d5d3d0 100644 --- a/src/keri/core/utils.ts +++ b/src/keri/core/utils.ts @@ -3,6 +3,7 @@ import { Seqner } from './seqner'; import { Prefixer } from './prefixer'; import { Saider } from './saider'; import { Serder } from './serder'; +import { b } from './core'; export function pad(n: any, width = 3, z = 0) { return (String(z).repeat(width) + String(n)).slice(String(n).length); @@ -116,33 +117,12 @@ export function bytesToInt(ar: Uint8Array): number { return value; } -export function serialize( - creder: any, - prefixer: any, - seqner: any, - saider: any -) { - let craw = creder.raw; - let ctr = new Counter({ code: CtrDex.SealSourceTriples, count: 1 }).qb64b; - let prefix = prefixer.qb64b; - let seq = seqner.qb64b; - let said = saider.qb64b; - let newCraw = new Uint8Array( - craw.length + ctr.length + prefix.length + seq.length + said.length - ); - newCraw.set(craw); - newCraw.set(ctr, craw.length); - newCraw.set(prefix, craw.length + ctr.length); - newCraw.set(seq, craw.length + ctr.length + prefix.length); - newCraw.set(said, craw.length + ctr.length + prefix.length + seq.length); - return newCraw; -} - export function serializeACDCAttachment( - prefixer: Prefixer, - seqner: Seqner, + acdc: Serder, saider: Saider ): Uint8Array { + let prefixer = new Prefixer({ raw: b(acdc.raw) }); + let seqner = new Seqner({ sn: acdc.sn }); let craw = new Uint8Array(); let ctr = new Counter({ code: CtrDex.SealSourceTriples, count: 1 }).qb64b; let prefix = prefixer.qb64b; diff --git a/test/core/utils.test.ts b/test/core/utils.test.ts new file mode 100644 index 00000000..40b294c2 --- /dev/null +++ b/test/core/utils.test.ts @@ -0,0 +1,38 @@ +import { Ident, Saider, Serder, Serials, d, versify } from '../../src'; +import { + serializeACDCAttachment, + serializeIssExnAttachment, +} from '../../src/keri/core/utils'; + +describe(serializeIssExnAttachment, () => { + it('serializes iss data', () => { + const [saider, data] = Saider.saidify({ + d: '', + v: versify(Ident.KERI, undefined, Serials.JSON, 0), + }); + + const result = serializeIssExnAttachment(new Serder(data), saider); + + expect(d(result)).toEqual( + '-VAS-GAB0AAAAAAAAAAAAAAAAAAAAAAAEKZPmzJqhx76bcC2ftPQgeRirmOd8ZBOtGVqHJrSm7F1' + ); + }); +}); + +describe(serializeACDCAttachment, () => { + it('serializes acdc data', () => { + const [saider, data] = Saider.saidify({ + d: '', + v: versify(Ident.ACDC, undefined, Serials.JSON, 0), + a: { + LEI: '123', + }, + }); + + const result = serializeACDCAttachment(new Serder(data), saider); + + expect(d(result)).toEqual( + '-IABBHsiZCI6IkVORTZzbWw4X1NMZVIzdk9NajRJRExLX2Nn0AAAAAAAAAAAAAAAAAAAAAAAENE6sml8_SLeR3vOMj4IDLK_cgd-A-vtg0Jnu7ozdBjW' + ); + }); +});