@wovin/core 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/applog/applog-helpers.d.ts +4 -4
- package/dist/applog/applog-helpers.d.ts.map +1 -1
- package/dist/applog.min.js +1 -1
- package/dist/chunk-5O6HLH5H.min.js +2 -0
- package/dist/chunk-5O6HLH5H.min.js.map +1 -0
- package/dist/chunk-6WLDICQ6.min.js +2 -0
- package/dist/chunk-6WLDICQ6.min.js.map +1 -0
- package/dist/chunk-O7KDPKK2.min.js +2 -0
- package/dist/chunk-O7KDPKK2.min.js.map +1 -0
- package/dist/chunk-XQUJRFOK.min.js +45 -0
- package/dist/{chunk-FPUMKLJ4.min.js.map → chunk-XQUJRFOK.min.js.map} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/mobx/mobx-utils.d.ts +19 -12
- package/dist/mobx/mobx-utils.d.ts.map +1 -1
- package/dist/pubsub/publication.d.ts +2 -2
- package/dist/pubsub/publication.d.ts.map +1 -1
- package/dist/pubsub.min.js +1 -1
- package/dist/query/basic.d.ts +28 -26
- package/dist/query/basic.d.ts.map +1 -1
- package/dist/query/divergences.d.ts +5 -5
- package/dist/query/divergences.d.ts.map +1 -1
- package/dist/query.min.js +1 -1
- package/dist/thread/basic.d.ts +36 -0
- package/dist/thread/basic.d.ts.map +1 -0
- package/dist/thread/filters.d.ts +40 -0
- package/dist/thread/filters.d.ts.map +1 -0
- package/dist/thread/mapped.d.ts +19 -0
- package/dist/thread/mapped.d.ts.map +1 -0
- package/dist/thread/writeable.d.ts +17 -0
- package/dist/thread/writeable.d.ts.map +1 -0
- package/dist/thread.d.ts +5 -0
- package/dist/thread.d.ts.map +1 -0
- package/dist/thread.min.js +2 -0
- package/dist/types/typescript-utils.d.ts +2 -2
- package/dist/types/typescript-utils.d.ts.map +1 -1
- package/dist/types.min.js +1 -1
- package/package.json +83 -83
- package/dist/chunk-3DTRPG63.min.js +0 -2
- package/dist/chunk-3DTRPG63.min.js.map +0 -1
- package/dist/chunk-FPUMKLJ4.min.js +0 -45
- package/dist/chunk-MBXUXVXG.min.js +0 -2
- package/dist/chunk-MBXUXVXG.min.js.map +0 -1
- package/dist/chunk-PMJNK5VR.min.js +0 -2
- package/dist/chunk-PMJNK5VR.min.js.map +0 -1
- package/dist/stream/basic.d.ts +0 -36
- package/dist/stream/basic.d.ts.map +0 -1
- package/dist/stream/filters.d.ts +0 -38
- package/dist/stream/filters.d.ts.map +0 -1
- package/dist/stream/mapped.d.ts +0 -19
- package/dist/stream/mapped.d.ts.map +0 -1
- package/dist/stream/writeable.d.ts +0 -17
- package/dist/stream/writeable.d.ts.map +0 -1
- package/dist/stream.d.ts +0 -5
- package/dist/stream.d.ts.map +0 -1
- package/dist/stream.min.js +0 -2
- /package/dist/{stream.min.js.map → thread.min.js.map} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Thread } from '../thread';
|
|
2
|
+
import { WriteableThread } from '../thread/writeable';
|
|
3
3
|
import { ApplogForInsert, ApplogForInsertOptionalAgent, ApplogNoCid, Timestamp } from './datom-types';
|
|
4
4
|
export declare function hasAg(log: ApplogForInsertOptionalAgent): log is ApplogForInsert;
|
|
5
5
|
export declare function hasTs(log: ApplogForInsert): log is Omit<ApplogForInsert, 'ts'> & {
|
|
@@ -11,7 +11,7 @@ export declare function hasPv(log: ApplogForInsert): log is ApplogForInsert & {
|
|
|
11
11
|
export declare function withTs(log: ApplogForInsert, ts: Timestamp): Omit<ApplogForInsert, "ts"> & {
|
|
12
12
|
ts: string;
|
|
13
13
|
};
|
|
14
|
-
export declare function withPv(log: ApplogNoCid, ds:
|
|
14
|
+
export declare function withPv(log: ApplogNoCid, ds: WriteableThread): {
|
|
15
15
|
pv: any;
|
|
16
16
|
ts: string;
|
|
17
17
|
ag: import("./datom-types").AgentHash;
|
|
@@ -19,5 +19,5 @@ export declare function withPv(log: ApplogNoCid, ds: WriteableApplogStream): {
|
|
|
19
19
|
at: string;
|
|
20
20
|
vl: import("./datom-types").ApplogValue;
|
|
21
21
|
};
|
|
22
|
-
export declare function
|
|
22
|
+
export declare function joinThreads(threads: Thread[]): Thread;
|
|
23
23
|
//# sourceMappingURL=applog-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applog-helpers.d.ts","sourceRoot":"","sources":["../../src/applog/applog-helpers.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"applog-helpers.d.ts","sourceRoot":"","sources":["../../src/applog/applog-helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgD,MAAM,EAAE,MAAM,WAAW,CAAA;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD,OAAO,EAAU,eAAe,EAAE,4BAA4B,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAI7G,wBAAgB,KAAK,CAAC,GAAG,EAAE,4BAA4B,GAAG,GAAG,IAAI,eAAe,CAE/E;AACD,wBAAgB,KAAK,CAAC,GAAG,EAAE,eAAe,GAAG,GAAG,IAAI,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,GAAG;IAAE,EAAE,EAAE,SAAS,CAAA;CAAE,CAElG;AACD,wBAAgB,KAAK,CAAC,GAAG,EAAE,eAAe,GAAG,GAAG,IAAI,eAAe,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAEnF;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,EAAE,EAAE,SAAS;;EAEzD;AACD,wBAAgB,MAAM,CAAC,GAAG,EAAE,WAAW,EAAE,EAAE,EAAE,eAAe;;;;;;;EAS3D;AACD,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,UAiC5C"}
|
package/dist/applog.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"./chunk-7IDQIMQO.min.js";import{$ as
|
|
1
|
+
import"./chunk-7IDQIMQO.min.js";import{$ as z,Aa as H,Ba as I,Ca as J,X as v,Y as w,Z as x,_ as y,aa as A,ba as B,ca as C,d as a,da as D,e as b,f as c,g as d,h as e,i as f,j as g,k as h,l as i,m as j,n as k,o as l,p as m,q as n,r as o,s as p,t as q,u as r,v as s,w as t,x as u,xa as E,ya as F,za as G}from"./chunk-XQUJRFOK.min.js";import"./chunk-G3GOAFHU.min.js";export{A as AppLogTB,B as AppLogTBC,y as CIDTB,x as EntityID,w as EntityID_LENGTH,v as Nullable,z as URL,p as actualize,f as areApplogsEqual,q as arrStats,t as arraysContainSameElements,b as compareApplogsByTs,s as cyrb53hash,u as dateNowIso,C as getApplogTypeErrors,h as getHashID,E as hasAg,G as hasPv,F as hasTs,k as isStaticPattern,d as isTsBefore,D as isValidApplog,i as isVariable,a as isoDateStrCompare,J as joinThreads,n as matchPart,m as matchPartStatic,o as matchPattern,g as removeDuplicateAppLogs,l as resolveOrRemoveVariables,c as sortApplogsByTs,r as tsNearlySame,e as uniqueEnFromAppLogs,j as variableNameWithoutQuestionmark,I as withPv,H as withTs};
|
|
2
2
|
//# sourceMappingURL=applog.min.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{J as T,V as y,W as c}from"./chunk-XQUJRFOK.min.js";import{b as p}from"./chunk-G3GOAFHU.min.js";var e=p(y(),1),a=p(c(),1);var b=a.TypeSystem.Type("Thread",(n,t)=>t instanceof T)(),{String:l,Optional:x,Boolean:f,Object:u,Number:m}=e.Type,o=l.bind(e.Type),r=m.bind(e.Type),O=u.bind(e.Type),g=x.bind(e.Type),d=f.bind(e.Type),S=o(),k=r(),P=d(),D=!0,N=!1;function h(){let n=o(),t=o(),s=r(),i=r();console.log({s1:n,s2:t,n1:s,n2:i})}export{b as a,o as b,r as c,O as d,g as e,d as f,S as g,k as h,P as i,D as j,N as k,h as l};
|
|
2
|
+
//# sourceMappingURL=chunk-5O6HLH5H.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/typescript-utils.ts"],"sourcesContent":["import { Type as T } from '@sinclair/typebox'\nimport { TypeSystem } from '@sinclair/typebox/system'\nimport type { CID } from 'multiformats'\nimport { Thread } from '../thread'\n\nexport const ThreadTB = TypeSystem.Type<Thread>('Thread', (options, value) => {\n\treturn value instanceof Thread\n})()\nconst { String: StringTB, Optional: OptionalTB, Boolean: BooleanTB, Object: ObjectTB, Number: NumberTB } = T\nexport const Str: typeof StringTB = StringTB.bind(T)\nexport const Num: typeof NumberTB = NumberTB.bind(T)\nexport const Obj: typeof ObjectTB = ObjectTB.bind(T)\nexport const Opt: typeof OptionalTB = OptionalTB.bind(T)\nexport const Bool: typeof BooleanTB = BooleanTB.bind(T)\n\nexport const STR: ReturnType<typeof T.String> = Str()\nexport const NUM: ReturnType<typeof T.Number> = Num()\nexport const BOOL: ReturnType<typeof T.Boolean> = Bool()\n\nexport type DefaultTrue = true | boolean\nexport const DefaultTrue: DefaultTrue = true\n\nexport type DefaultFalse = false | boolean\nexport const DefaultFalse: DefaultFalse = false\n\nexport type GenericObject = Record<string, any>\nexport type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>\nexport type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>\nexport type PromiseType<T extends Promise<any>> = T extends Promise<infer U> ? U : never\n\nexport type CoerceToString<T> = T extends string ? T : never\n\n/**\n * Define nominal type of U based on type of T. Similar to Opaque types in Flow\n */\nexport type Tagged<T, Tag> = T & { tag?: Tag }\n\n// export interface Service {\n// \tendpoint?: URL\n// \ttoken: string\n// \trateLimiter?: RateLimiter\n// \tfetch?: typeof _fetch\n// }\n\n// https://stackoverflow.com/a/76276541\nexport type LastElementOf<T extends readonly unknown[]> = T extends readonly [...unknown[], infer Last] ? Last : never\n\nexport function checkParityTB() {\n\t/* Most examples are constantly calling Type.*() - needed to check if its really needed\n https://github.com/sinclairzx81/typebox/issues/587#issuecomment-1712457623\n */\n\tconst s1 = Str()\n\tconst s2 = Str()\n\tconst n1 = Num()\n\tconst n2 = Num()\n\tconsole.log({ s1, s2, n1, n2 })\n}\n\n/** solidjs Setter requires returning something, which I often don't */\nexport type GenericSetter<T> = (newValue: T) => void\n"],"mappings":"sGAAA,IAAAA,EAA0B,SAC1BC,EAA2B,SAIpB,IAAMC,EAAW,aAAW,KAAa,SAAU,CAACC,EAASC,IAC5DA,aAAiBC,CACxB,EAAE,EACG,CAAE,OAAQC,EAAU,SAAUC,EAAY,QAASC,EAAW,OAAQC,EAAU,OAAQC,CAAS,EAAI,EAAAC,KAC9FC,EAAuBN,EAAS,KAAK,EAAAK,IAAC,EACtCE,EAAuBH,EAAS,KAAK,EAAAC,IAAC,EACtCG,EAAuBL,EAAS,KAAK,EAAAE,IAAC,EACtCI,EAAyBR,EAAW,KAAK,EAAAI,IAAC,EAC1CK,EAAyBR,EAAU,KAAK,EAAAG,IAAC,EAEzCM,EAAmCL,EAAI,EACvCM,EAAmCL,EAAI,EACvCM,EAAqCH,EAAK,EAG1CI,EAA2B,GAG3BC,EAA6B,GAwBnC,SAASC,GAAgB,CAI/B,IAAMC,EAAKX,EAAI,EACTY,EAAKZ,EAAI,EACTa,EAAKZ,EAAI,EACTa,EAAKb,EAAI,EACf,QAAQ,IAAI,CAAE,GAAAU,EAAI,GAAAC,EAAI,GAAAC,EAAI,GAAAC,CAAG,CAAC,CAC/B","names":["import_typebox","import_system","ThreadTB","options","value","Thread","StringTB","OptionalTB","BooleanTB","ObjectTB","NumberTB","T","Str","Num","Obj","Opt","Bool","STR","NUM","BOOL","DefaultTrue","DefaultFalse","checkParityTB","s1","s2","n1","n2"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{D as c,G as v,a as g,b as m,c as f,fa as u,y as l}from"./chunk-XQUJRFOK.min.js";import{c as p}from"./chunk-G3GOAFHU.min.js";var{WARN:d,LOG:x,DEBUG:y,VERBOSE:i,ERROR:A}=p.setup(p.INFO),L=v("queryDivergencesByPrev",function(e){y(`queryDivergencesByPrev<${e.nameAndSizeUntracked}>`),e.filters.includes("lastWriteWins")&&d("queryDivergencesByPrev on thread lastWriteWins",e);let s=c(()=>{let a=new Map,n=new Set;i("all applogs:",e.applogs);for(let r of e.applogs){let t;r.pv&&(t=r.pv&&a.get(r.pv.toString()),n.delete(r.pv.toString())),i("traversing log",{log:r,prevLogs:t,leafs:Array.from(n)}),a.set(r.cid,t?[...t,r]:[r]),n.add(r.cid)}return Array.from(n).map(r=>{let t=new u(a.get(r),e.filters,l({caller:"DivergenceLeaf",thread:e,pattern:`leaf: ${r}`}),!0,e);return{log:t.latestLog,thread:t}})},{name:l({caller:"queryDivergencesByPrev",thread:e})});return i.isDisabled||m(()=>i("[queryDivergencesByPrev] result:",f(s))),s},{equals:g.structural});function R(o){return e=>e?.includes?.(o)}function W(o){return e=>o?.includes?.(e)}export{L as a,R as b,W as c};
|
|
2
|
+
//# sourceMappingURL=chunk-6WLDICQ6.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/query/divergences.ts","../src/query/matchers.ts"],"sourcesContent":["import { Logger } from 'besonders-logger'\nimport { autorun, comparer, toJS } from 'mobx'\nimport { Applog } from '../applog/datom-types'\nimport { computedFnDeepCompare, createDebugName, observableArrayMap } from '../mobx/mobx-utils'\nimport { Thread } from '../thread'\nimport { ThreadInMemory } from '../thread/writeable'\n\nconst { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.INFO) // eslint-disable-line no-unused-vars\n\nexport interface DivergenceLeaf {\n\tlog: Applog\n\tthread: Thread\n}\n\nexport const queryDivergencesByPrev = computedFnDeepCompare('queryDivergencesByPrev', function queryConflictingByPrev(\n\tsourceThread: Thread,\n) {\n\tDEBUG(`queryDivergencesByPrev<${sourceThread.nameAndSizeUntracked}>`)\n\tif (sourceThread.filters.includes('lastWriteWins')) WARN(`queryDivergencesByPrev on thread lastWriteWins`, sourceThread)\n\n\tconst divergences = observableArrayMap(() => {\n\t\tconst logsForNode = new Map<string, Applog[]>()\n\t\tconst leafs = new Set<string>()\n\t\tVERBOSE('all applogs:', sourceThread.applogs)\n\t\tfor (const log of sourceThread.applogs) {\n\t\t\tlet prevLogs\n\t\t\tif (log.pv) {\n\t\t\t\tprevLogs = log.pv && logsForNode.get(log.pv.toString())\n\t\t\t\tleafs.delete(log.pv.toString())\n\t\t\t}\n\t\t\tVERBOSE('traversing log', { log, prevLogs, leafs: Array.from(leafs) })\n\t\t\tlogsForNode.set(log.cid, prevLogs ? [...prevLogs, log] : [log])\n\t\t\tleafs.add(log.cid)\n\t\t}\n\t\treturn Array.from(leafs).map(leafID => {\n\t\t\t// TODO use MappedThread?\n\t\t\tconst thread = new ThreadInMemory(\n\t\t\t\tlogsForNode.get(leafID),\n\t\t\t\tsourceThread.filters,\n\t\t\t\tcreateDebugName({\n\t\t\t\t\tcaller: 'DivergenceLeaf',\n\t\t\t\t\tthread: sourceThread,\n\t\t\t\t\tpattern: `leaf: ${leafID}`,\n\t\t\t\t}),\n\t\t\t\ttrue,\n\t\t\t\tsourceThread,\n\t\t\t)\n\t\t\treturn ({ log: thread.latestLog, thread })\n\t\t})\n\t}, { name: createDebugName({ caller: 'queryDivergencesByPrev', thread: sourceThread }) })\n\tVERBOSE.isDisabled || autorun(() => VERBOSE(`[queryDivergencesByPrev] result:`, toJS(divergences)))\n\treturn divergences\n}, { equals: comparer.structural })\n","import { DatomPart } from '../applog/datom-types'\n\nexport function includes(str: string) {\n\treturn (vl: DatomPart) => vl?.includes?.(str)\n}\nexport function includedIn(arr: string[]) {\n\treturn (vl: DatomPart) => arr?.includes?.(vl)\n}\n"],"mappings":"mIAOA,GAAM,CAAE,KAAAA,EAAM,IAAAC,EAAK,MAAAC,EAAO,QAAAC,EAAS,MAAAC,CAAM,EAAIC,EAAO,MAAMA,EAAO,IAAI,EAOxDC,EAAyBC,EAAsB,y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AAkBE,GAAK,WAAWF,CAAE,CAC7C","names":["WARN","LOG","DEBUG","VERBOSE","ERROR","Logger","queryDivergencesByPrev","computedFnDeepCompare","sourceThread","divergences","observableArrayMap","logsForNode","leafs","log","prevLogs","leafID","thread","ThreadInMemory","createDebugName","autorun","toJS","comparer","includes","str","vl","includedIn","arr"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{d as h}from"./chunk-J5PGGKKW.min.js";import{K as D,M as S,ia as T,v as w}from"./chunk-XQUJRFOK.min.js";import{c as f,l as C,q as c}from"./chunk-G3GOAFHU.min.js";var{WARN:O,LOG:H,DEBUG:i,VERBOSE:x,ERROR:m}=f.setup(f.DEBUG);async function M(t,n,o,p){let e=D(o),{sharedAgents:d,sharedKeyMap:l,sharedKey:s}=p??{},a=S(T(n),{en:t.ag,at:["agent/ecdh","agent/jwkd","agent/appAgent"]}).applogs;if(i("[preparePubForPush] agent logs:",a),!a.find(({at:r})=>r==="agent/appAgent"))throw m("[preparePubForPush] appThread missing agent/appAgent log");let u,y=async(r,P)=>{throw new Error("todo: enc")};i("[preparePubForPush] applogs ",e);let g;if(d){if(!s||!l)throw m("sharedAgents but no Keys/Map",{sharedAgents:d,sharedKeyMap:l,sharedKey:s});let r=[],P=[];for(let[A,I]of Array.from(l.entries()))P.push({ag:t.ag,en:A,at:"pub/sharedKey",vl:I});for(let A of e){x("[crypto] encrypting ",A);try{u=await y(A,s)}catch{}r.push(u)}g=r}else g=e;return U(t,g,a)}async function U(t,n,o){i("[encodePubAsCar] encoding",{agent:t,applogs:n,infoLogs:o});let{cids:p,encodedApplogs:e}=await b(o),{cids:d,encodedApplogs:l}=await b(n),s=await c({logs:p}),a=await c({logs:d}),u=await t.sign(s.bytes),y=await t.sign(a.bytes),g={info:s.cid,applogs:a.cid,infoSignature:u,applogsSignature:y};i("[encodePubAsCar] encoding root",{root:g,logCids:d,infoLogCids:p});let r=await c(g);return i("[encodePubAsCar] => root",{encodedRoot:r}),await h(r.cid,[r,s,a,...e,...l])}async function G(t){let{cids:n,encodedApplogs:o}=await b(t),e=await c({applogs:n});return i("[encodeApplogsAsCar] encoded root",{cids:n,encodedRoot:e}),await h(e.cid,[e,...o])}async function b(t){let n=t.map(e=>e instanceof Uint8Array?e:C(e)),o=await Promise.all(n.map(c));return i("[encodeApplogsAsIpld] encoded applogs",{encodedApplogs:o}),{cids:o.map(e=>{if(!e.cid)throw new m("[publish] no cid for encoded log:",e);return e.cid}),encodedApplogs:o}}function N(t){return t?.pk!==void 0&&t?.lastPush!==void 0}function V(t){return t?.lastPull!==void 0}function q(t){return w(t,31,7)}export{M as a,U as b,G as c,N as d,V as e,q as f};
|
|
2
|
+
//# sourceMappingURL=chunk-O7KDPKK2.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pubsub/publication.ts","../src/pubsub/pubsub-types.ts"],"sourcesContent":["import { Logger } from 'besonders-logger'\nimport { stringify } from 'safe-stable-stringify'\nimport { cyrb53hash } from '../applog/applog-utils'\nimport { Applog, ApplogForInsert, EntityID } from '../applog/datom-types'\nimport { makeCarBlob } from '../ipfs/car'\nimport { encodeBlockOriginal, prepareForPub } from '../ipfs/ipfs-utils'\nimport { lastWriteWins } from './../query/basic'\nimport { ApplogsOrThread, getLogsFromThread, Thread } from '../thread'\nimport { rollingFilter } from '../thread/filters'\nimport { AppAgent, IPublication } from './pubsub-types'\n\nconst { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.DEBUG) // eslint-disable-line no-unused-vars\n\n// export const neverEncryptAttrs = [\n// \t'agent/jwkd',\n// \t'agent/appAgent',\n// \t'pub/encryptedFor',\n// \t'pub/sharedKey',\n// ]\n\nexport async function preparePubForPush(\n\tagent: AppAgent,\n\tappThread: Thread,\n\tthreadToPublish: ApplogsOrThread,\n\tpublication: IPublication,\n) {\n\t// await initWasm()\n\t// const car_data = Wasm.make_car(applogs)\n\t// DEBUG('Car data:', car_data)\n\t// TODO prevent publish if there is no new info\n\tconst logsToPublish = getLogsFromThread(threadToPublish)\n\n\tconst { sharedAgents, sharedKeyMap, sharedKey } = publication ?? {}\n\t// TODO: publish all agents' info related to the logs we want to publish\n\tconst agentLogs = rollingFilter(lastWriteWins(appThread), {\n\t\ten: agent.ag,\n\t\tat: ['agent/ecdh', 'agent/jwkd', 'agent/appAgent'],\n\t}).applogs\n\tDEBUG(`[preparePubForPush] agent logs:`, agentLogs)\n\tif (!agentLogs.find(({ at }) => at === 'agent/appAgent')) throw ERROR(`[preparePubForPush] appThread missing agent/appAgent log`)\n\tlet encPayload\n\tconst encryptAndTestDecrypt = async (applog: Applog, keyToUse: CryptoKey): Promise<Uint8Array> => {\n\t\tthrow new Error(`todo: enc`) // TODO: ENC\n\t\t// const eachLog = prepareForPub(applog) // without cid\n\t\t// const enc = new TextEncoder()\n\t\t// const stringified = stringify(eachLog)\n\t\t// const stringifiedEncodedAppLogPayload = enc.encode(stringified) // TODO: consider encodeToDagJson instead\n\t\t// VERBOSE('[odd]', { eachLog, stringified, stringifiedEncodedAppLogPayload })\n\n\t\t// try {\n\t\t// \tencPayload = await agent.crypto?.aes.encrypt(stringifiedEncodedAppLogPayload, keyToUse, SymmAlg.AES_GCM)\n\t\t// } catch (err) {\n\t\t// \tthrow ERROR('FAILED TO ENC payload length:', stringifiedEncodedAppLogPayload.length, { err })\n\t\t// }\n\n\t\t// const decrypted = await decryptWithAesSharedKey(encPayload, keyToUse, 'string')\n\n\t\t// VERBOSE('[odd] encrypted length:', stringifiedEncodedAppLogPayload.length, { encPayload, decrypted })\n\t\t// return encPayload\n\t}\n\tDEBUG('[preparePubForPush] applogs ', logsToPublish)\n\n\tlet maybeEncryptedApplogs: Uint8Array[] | readonly Applog[]\n\tif (sharedAgents) { // encrypt all Applogs\n\t\tif (!sharedKey || !sharedKeyMap) {\n\t\t\tthrow ERROR('sharedAgents but no Keys/Map', { sharedAgents, sharedKeyMap, sharedKey })\n\t\t}\n\t\tconst encryptedApplogs = [] as Uint8Array[]\n\t\tconst agentSharedKeyLogs = []\n\t\tfor (const [eachAgent, eachEncKey] of Array.from(sharedKeyMap.entries())) {\n\t\t\tagentSharedKeyLogs.push({\n\t\t\t\tag: agent.ag,\n\t\t\t\ten: eachAgent,\n\t\t\t\tat: 'pub/sharedKey',\n\t\t\t\tvl: eachEncKey, // these are encrypted with the derived key from the local agent private and remote agent public keys\n\t\t\t})\n\t\t}\n\t\t// const encryptedForLogs = await insertApplogs(agentSharedKeyLogs)\n\t\t// DEBUG(`[publish] adding agentSharedKeyLogs:`, encryptedForLogs)\n\n\t\t// TODO ensure that all needed keys are in\n\t\tfor (const eachLog of logsToPublish) {\n\t\t\tVERBOSE('[crypto] encrypting ', eachLog)\n\t\t\t// if (neverEncryptAttrs.includes(eachLog.at)) {\n\t\t\t// \tencryptedApplogs.push(/* prepareForPub( */ eachLog /* ) */) // ? this seemed to double the below one - @gotjoshua?\n\t\t\t// \t// continue\n\t\t\t// }\n\t\t\ttry {\n\t\t\t\tencPayload = await encryptAndTestDecrypt(eachLog, sharedKey)\n\t\t\t} catch (err) {\n\t\t\t\t// its already traced in encryptAndTestDecrypt\n\t\t\t\t// continue\n\t\t\t}\n\t\t\tencryptedApplogs.push(encPayload)\n\t\t}\n\t\tmaybeEncryptedApplogs = encryptedApplogs\n\t} else {\n\t\tmaybeEncryptedApplogs = logsToPublish // publish nonEncrypted\n\t}\n\treturn encodePubAsCar(agent, maybeEncryptedApplogs, agentLogs)\n}\n\n/**\n * @param applogs Encrypted or plain applogs\n * @returns Car file\n */\nexport async function encodePubAsCar(\n\tagent: AppAgent,\n\tapplogs: readonly Uint8Array[] | readonly Applog[],\n\tinfoLogs: readonly Applog[],\n) {\n\tDEBUG(`[encodePubAsCar] encoding`, { agent, applogs, infoLogs })\n\tconst { cids: infoLogCids, encodedApplogs: encodedInfoLogs } = await encodeApplogsAsIPLD(infoLogs)\n\tconst { cids: logCids, encodedApplogs } = await encodeApplogsAsIPLD(applogs)\n\t// We need to wrap the array to get a CID\n\tconst infoLogsWrap = await encodeBlockOriginal({ logs: infoLogCids })\n\tconst applogsWrap = await encodeBlockOriginal({ logs: logCids })\n\tconst infoSignature = await agent.sign(infoLogsWrap.bytes)\n\tconst applogsSignature = await agent.sign(applogsWrap.bytes)\n\tconst root = {\n\t\tinfo: infoLogsWrap.cid,\n\t\tapplogs: applogsWrap.cid,\n\t\tinfoSignature,\n\t\tapplogsSignature,\n\t}\n\tDEBUG('[encodePubAsCar] encoding root', { root, logCids, infoLogCids })\n\tconst encodedRoot = await encodeBlockOriginal(root)\n\tDEBUG('[encodePubAsCar] => root', { encodedRoot })\n\n\treturn await makeCarBlob(encodedRoot.cid, [encodedRoot, infoLogsWrap, applogsWrap, ...encodedInfoLogs, ...encodedApplogs]) // TODO: create CarBuilder\n}\n\n/**\n * @param applogs Encrypted or plain applogs\n * @returns Car file\n */\nexport async function encodeApplogsAsCar(\n\tapplogs: readonly Uint8Array[] | readonly Applog[],\n) {\n\tconst { cids, encodedApplogs } = await encodeApplogsAsIPLD(applogs)\n\tconst root = { applogs: cids }\n\tconst encodedRoot = await encodeBlockOriginal(root)\n\tDEBUG('[encodeApplogsAsCar] encoded root', { cids, encodedRoot })\n\n\treturn await makeCarBlob(encodedRoot.cid, [encodedRoot, ...encodedApplogs])\n}\n\nasync function encodeApplogsAsIPLD(applogs: readonly Applog[] | readonly Uint8Array[]) {\n\tconst preppedLogs = applogs.map(log => log instanceof Uint8Array ? log : prepareForPub(log as Applog))\n\tconst encodedApplogs = await Promise.all(preppedLogs.map(encodeBlockOriginal))\n\tDEBUG('[encodeApplogsAsIpld] encoded applogs', { encodedApplogs })\n\n\tconst cids = encodedApplogs.map(b => {\n\t\tif (!b.cid) throw new ERROR(`[publish] no cid for encoded log:`, b)\n\t\treturn b.cid\n\t})\n\treturn { cids, encodedApplogs }\n}\n","import { cyrb53hash } from './../applog/applog-utils'\nimport { AgentHash, AgentID } from '../applog/datom-types'\nimport { Tagged } from '../types'\n\ntype AgentString = Tagged<string, 'AgentString'>\ntype DIDString = Tagged<string, 'DID'>\nexport type { AgentHash, AgentString, DIDString }\n\nexport interface AppAgent {\n\tag: AgentHash\n\tagentString: AgentString\n\tdid: DIDString\n\n\tsign(data: Uint8Array): Promise<Uint8Array>\n}\n\nexport interface IPublication {\n\tid?: string // string hash of pub (used as unique id in IDB) `W3Name.create().toString()` starts with k51qzi5uqu5d\n\tcreatedAt: string // ISO timestamp of creation\n\tname: string // nick name for the pub\n\tisDeleted?: boolean\n\n\tpk: Uint8Array // exported privatekey - needed to create WritableName for publishing //TODO: store as non-extractable / encrypted?\n\n\tautopush: boolean\n\tlastPush: string | null\n\tlastCID?: string\n\tlatestLogTs?: string\n\n\tpublishedBy: string // local user appAgent\n\tselectors?: string[] // to be used as a filter for which applogs to pub\n\tencryptedFor?: string | null // short agentHash\n\tencryptedWith?: CryptoKey | null // AES-GCM derived key from ECDH keys (local private and remote public)\n\n\t// HACK WIP #39 - shared encryption\n\tsharedKey?: CryptoKey | null // AES-GCM derived key from ECDH keys (local private and ipns public)\n\tsharedAgents?: AgentID[] | null // array of string EntityIDs for the chosen agents (we need public jwkd atoms for each of them)\n\tsharedKeyMap?: Map<AgentID, string> | null // uses public key from each agent to derive an aes key that is used to encrypt and btoa the sharedKey that is actually used to encrypt and decrypt the applogs\n}\nexport interface ISubscription {\n\tid: string // string hash of pub (used as unique id in IDB) `W3Name.create().toString()` starts with k51qzi5uqu5d\n\tcreatedAt: string // ISO timestamp of creation\n\tname: string // nick name for the pub\n\tisDeleted: boolean\n\n\tlastPull?: string | null\n\tlastPullAttempt?: string | null\n\tautopull: boolean\n\tlastCID?: string\n\tpublishedBy?: string // remote publisher short agentHash\n\tencryptedFor?: string | undefined // short agentHash\n\tencryptedWith?: CryptoKey | undefined // AES-GCM derived key from ECDH keys (local private and remote public)\n}\nexport function isPublication(obj: any): obj is IPublication {\n\treturn obj?.pk !== undefined && obj?.lastPush !== undefined\n}\nexport function isSubscription(obj: any): obj is ISubscription {\n\treturn obj?.lastPull !== undefined\n}\n\nexport type TSubPub = IPublication | ISubscription\n\nexport function agentToShortHash(agentString: string) {\n\treturn cyrb53hash(agentString, 31, 7) as string\n}\n"],"mappings":"wKAWA,GAAM,CAAE,KAAAA,EAAM,IAAAC,EAAK,MAAAC,EAAO,QAAAC,EAAS,MAAAC,CAAM,EAAIC,EAAO,MAAMA,EAAO,KAAK,EAStE,eAAsBC,EACrBC,EACAC,EACAC,EACAC,EACC,CAKD,IAAMC,EAAgBC,EAAkBH,CAAe,EAEjD,CAAE,aAAAI,EAAc,aAAAC,EAAc,UAAAC,CAAU,EAAIL,GAAe,CAAC,EAE5DM,EAAYC,EAAcC,EAAcV,CAAS,EAAG,CACzD,GAAID,EAAM,GACV,GAAI,CAAC,aAAc,aAAc,gBAAgB,CAClD,CAAC,EAAE,QAEH,GADAL,EAAM,kCAAmCc,CAAS,EAC9C,CAACA,EAAU,KAAK,CAAC,CAAE,GAAAG,CAAG,IAAMA,IAAO,gBAAgB,EAAG,MAAMf,EAAM,0DAA0D,EAChI,IAAIgB,EACEC,EAAwB,MAAOC,EAAgBC,IAA6C,CACjG,MAAM,IAAI,MAAM,WAAW,CAiB5B,EACArB,EAAM,+BAAgCS,CAAa,EAEnD,IAAIa,EACJ,GAAIX,EAAc,CACjB,GAAI,CAACE,GAAa,CAACD,EAClB,MAAMV,EAAM,+BAAgC,CAAE,aAAAS,EAAc,aAAAC,EAAc,UAAAC,CAAU,CAAC,EAEtF,IAAMU,EAAmB,CAAC,EACpBC,EAAqB,CAAC,EAC5B,OAAW,CAACC,EAAWC,CAAU,IAAK,MAAM,KAAKd,EAAa,QAAQ,CAAC,EACtEY,EAAmB,KAAK,CACvB,GAAInB,EAAM,GACV,GAAIoB,EACJ,GAAI,gBACJ,GAAIC,CACL,CAAC,EAMF,QAAWC,KAAWlB,EAAe,CACpCR,EAAQ,uBAAwB0B,CAAO,EAKvC,GAAI,CACHT,EAAa,MAAMC,EAAsBQ,EAASd,CAAS,CAC5D,M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C,CAC3E,CAEA,eAAeF,EAAoBJ,EAAoD,CACtF,IAAMiB,EAAcjB,EAAQ,IAAIkB,GAAOA,aAAe,WAAaA,EAAMC,EAAcD,CAAa,CAAC,EAC/FZ,EAAiB,MAAM,QAAQ,IAAIW,EAAY,IAAIT,CAAmB,CAAC,EAC7E,OAAArC,EAAM,wCAAyC,CAAE,eAAAmC,CAAe,CAAC,EAM1D,CAAE,KAJIA,EAAe,IAAIc,GAAK,CACpC,GAAI,CAACA,EAAE,IAAK,MAAM,IAAI/C,EAAM,oCAAqC+C,CAAC,EAClE,OAAOA,EAAE,GACV,CAAC,EACc,eAAAd,CAAe,CAC/B,CCxGO,SAASe,EAAcC,EAA+B,CAC5D,OAAOA,GAAK,KAAO,QAAaA,GAAK,WAAa,MACnD,CACO,SAASC,EAAeD,EAAgC,CAC9D,OAAOA,GAAK,WAAa,MAC1B,CAIO,SAASE,EAAiBC,EAAqB,CACrD,OAAOC,EAAWD,EAAa,GAAI,CAAC,CACrC","names":["WARN","LOG","DEBUG","VERBOSE","ERROR","Logger","preparePubForPush","agent","appThread","threadToPublish","publication","logsToPublish","getLogsFromThread","sharedAgents","sharedKeyMap","sharedKey","agentLogs","rollingFilter","lastWriteWins","at","encPayload","encryptAndTestDecrypt","applog","keyToUse","maybeEncryptedApplogs","encryptedApplogs","agentSharedKeyLogs","eachAgent","eachEncKey","eachLog","encodePubAsCar","applogs","infoLogs","infoLogCids","encodedInfoLogs","encodeApplogsAsIPLD","logCids","encodedApplogs","infoLogsWrap","encodeBlockOriginal","applogsWrap","infoSignature","applogsSignature","root","encodedRoot","makeCarBlob","encodeApplogsAsCar","cids","preppedLogs","log","prepareForPub","b","isPublication","obj","isSubscription","agentToShortHash","agentString","cyrb53hash"]}
|