@wovin/core 0.0.2 → 0.0.3-RC2

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.
@@ -0,0 +1,2 @@
1
+ import{d as b}from"./chunk-NGPPHX5A.min.js";import{Q as h}from"./chunk-5R2ELTEJ.min.js";import{d as c,m as A,r as u}from"./chunk-KESATLM4.min.js";var{WARN:C,LOG:k,DEBUG:p,VERBOSE:P,ERROR:D}=c.setup(c.INFO),K=["agent/jwkd","agent/appAgent","pub/encryptedFor","pub/sharedKey"];async function L(r,n,i,s,d){let e=[],{sharedAgents:t,sharedKeyMap:a,sharedKey:l}=d??{},g=h(r,{en:i,at:["agent/ecdh","agent/jwkd","agent/appAgent"]});p("[publish] adding agent logs:",g),n.push(...g.applogs);let y,I=async(f,o)=>{throw new Error("todo: enc")};if(p("[publish] applogs ",n),t)if(!l||!a)p("weird state, publishing nonEncrypted",{sharedAgents:t,sharedKeyMap:a,sharedKey:l}),e=n;else{let f=[];for(let[o,m]of Array.from(a.entries()))f.push({ag:i,en:o,at:"pub/sharedKey",vl:m});for(let o of n){P("[crypto] encrypting ",o),K.includes(o.at)&&e.push(o);try{y=await I(o,l)}catch{}e.push(y)}}else e=n;return w(e)}async function w(r){let n=r.map(t=>t instanceof Uint8Array?t:A(t)),i=await Promise.all(n.map(u));p("[publish] encoded applogs",{encodedApplogs:i});let s=i.map(t=>{if(!t.cid)throw new D("[publish] no cid for encoded log:",t);return t.cid}),e=await u({applogs:s});return p("[publish] encoded root",{cids:s,encodedRoot:e}),await b(e.cid,[e,...i])}function B(r){return r?.pk!==void 0&&r?.lastPush!==void 0}function R(r){return r?.lastPull!==void 0}export{K as a,L as b,w as c,B as d,R as e};
2
+ //# sourceMappingURL=chunk-HNATM27J.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 { ApplogStream } from '../stream'\nimport { rollingFilter } from '../stream/filters'\nimport { IPublication } from './pubsub-types'\n\nconst { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.INFO) // eslint-disable-line no-unused-vars\n\nexport 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\tdataStream: ApplogStream,\n\tapplogs: Applog[],\n\tagentHash: EntityID,\n\tagentFullID: string,\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\tlet maybeEncryptedApplogs: Array<Applog | Uint8Array> = []\n\n\tconst { sharedAgents, sharedKeyMap, sharedKey } = publication ?? {}\n\tconst agentLogs = rollingFilter(dataStream, {\n\t\ten: agentHash,\n\t\tat: ['agent/ecdh', 'agent/jwkd', 'agent/appAgent'],\n\t})\n\tDEBUG(`[publish] adding agent logs:`, agentLogs)\n\tapplogs.push(...agentLogs.applogs)\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('[publish] applogs ', applogs)\n\n\tif (sharedAgents) { // encrypt all Applogs\n\t\tif (!sharedKey || !sharedKeyMap) {\n\t\t\tDEBUG('weird state, publishing nonEncrypted', { sharedAgents, sharedKeyMap, sharedKey }) // ? could this be a problem\n\t\t\tmaybeEncryptedApplogs = applogs\n\t\t} else {\n\t\t\tconst agentSharedKeyLogs = []\n\t\t\tfor (const [eachAgent, eachEncKey] of Array.from(sharedKeyMap.entries())) {\n\t\t\t\tagentSharedKeyLogs.push({\n\t\t\t\t\tag: agentHash,\n\t\t\t\t\ten: eachAgent,\n\t\t\t\t\tat: 'pub/sharedKey',\n\t\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\t})\n\t\t\t}\n\t\t\t// const encryptedForLogs = await insertApplogs(agentSharedKeyLogs)\n\t\t\t// DEBUG(`[publish] adding agentSharedKeyLogs:`, encryptedForLogs)\n\n\t\t\t// TODO ensure that all needed keys are in\n\t\t\tfor (const eachLog of applogs) {\n\t\t\t\tVERBOSE('[crypto] encrypting ', eachLog)\n\t\t\t\tif (neverEncryptAttrs.includes(eachLog.at)) {\n\t\t\t\t\tmaybeEncryptedApplogs.push(/* prepareForPub( */ eachLog /* ) */) // ? this seemed to double the below one - @gotjoshua?\n\n\t\t\t\t\t// continue\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tencPayload = await encryptAndTestDecrypt(eachLog, sharedKey)\n\t\t\t\t} catch (err) {\n\t\t\t\t\t// its already traced in encryptAndTestDecrypt\n\t\t\t\t\t// continue\n\t\t\t\t}\n\t\t\t\tmaybeEncryptedApplogs.push(encPayload)\n\t\t\t}\n\t\t}\n\t} else maybeEncryptedApplogs = applogs // publish nonEncrypted\n\n\treturn encodeApplogsAsCar(maybeEncryptedApplogs)\n}\n\nexport async function encodeApplogsAsCar(\n\tapplogs: Array<Applog | Uint8Array>,\n) {\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('[publish] 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\tconst root = { applogs: cids }\n\tconst encodedRoot = await encodeBlockOriginal(root)\n\tDEBUG('[publish] encoded root', { cids, encodedRoot })\n\n\treturn await makeCarBlob(encodedRoot.cid, [encodedRoot, ...encodedApplogs])\n}\n","import { AgentID } from '../applog/datom-types'\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\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"],"mappings":"kJAUA,GAAM,CAAE,KAAAA,EAAM,IAAAC,EAAK,MAAAC,EAAO,QAAAC,EAAS,MAAAC,CAAM,EAAIC,EAAO,MAAMA,EAAO,IAAI,EAExDC,EAAoB,CAChC,aACA,iBACA,mBACA,eACD,EAEA,eAAsBC,EACrBC,EACAC,EACAC,EACAC,EACAC,EACC,CAKD,IAAIC,EAAoD,CAAC,EAEnD,CAAE,aAAAC,EAAc,aAAAC,EAAc,UAAAC,CAAU,EAAIJ,GAAe,CAAC,EAC5DK,EAAYC,EAAcV,EAAY,CAC3C,GAAIE,EACJ,GAAI,CAAC,aAAc,aAAc,gBAAgB,CAClD,CAAC,EACDR,EAAM,+BAAgCe,CAAS,EAC/CR,EAAQ,KAAK,GAAGQ,EAAU,OAAO,EACjC,IAAIE,EACEC,EAAwB,MAAOC,EAAgBC,IAA6C,CACjG,MAAM,IAAI,MAAM,WAAW,CAiB5B,EAGA,GAFApB,EAAM,qBAAsBO,CAAO,EAE/BK,EACH,GAAI,CAACE,GAAa,CAACD,EAClBb,EAAM,uCAAwC,CAAE,aAAAY,EAAc,aAAAC,EAAc,UAAAC,CAAU,CAAC,EACvFH,EAAwBJ,MAClB,CACN,IAAMc,EA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publication","maybeEncryptedApplogs","sharedAgents","sharedKeyMap","sharedKey","agentLogs","rollingFilter","encPayload","encryptAndTestDecrypt","applog","keyToUse","agentSharedKeyLogs","eachAgent","eachEncKey","eachLog","encodeApplogsAsCar","preppedLogs","log","prepareForPub","encodedApplogs","encodeBlockOriginal","cids","b","encodedRoot","makeCarBlob","isPublication","obj","isSubscription"]}
package/dist/index.min.js CHANGED
@@ -1,2 +1,2 @@
1
- import"./chunk-7IDQIMQO.min.js";import"./chunk-RPPZKO5L.min.js";import{a as Fo,b as Go,c as Ho,d as Io}from"./chunk-PL6CNZTW.min.js";import{a as Ao,b as Bo,c as Do,d as Eo}from"./chunk-NGPPHX5A.min.js";import{a as Jo,b as Ko,c as Lo}from"./chunk-LECZSORU.min.js";import{a as Mo,b as No,c as Oo,d as Po,e as Qo,f as Ro,g as So,h as Uo,i as Vo,j as Wo,k as Xo,l as Yo}from"./chunk-F3MRAJXL.min.js";import{A as bo,B as go,C as ho,D as jo,E as ko,F as lo,G as qo,H as uo,I as yo,J as zo,c as O,d as P,e as Q,f as R,g as S,h as U,i as V,j as W,k as X,l as eo,m as to,n as po,o as xo,p as fo,q as mo,r as no,s as so,t as co,u as io,v as vo,w as wo,x as Co,y as To,z as ao}from"./chunk-HHXZXKNM.min.js";import{A as a,B as b,C as d,D as g,E as h,F as j,G as k,H as l,I as q,J as u,K as y,L as z,M as A,N as B,O as D,P as E,Q as F,R as G,S as H,T as I,U as J,V as K,W as L,X as M,Y as N,k as o,l as r,m as e,n as t,o as p,p as x,q as f,r as m,s as n,t as s,u as c,v as i,w as v,x as w,y as C,z as T}from"./chunk-5R2ELTEJ.min.js";import{m as Y,n as Z,o as _,p as $,q as oo,r as ro}from"./chunk-KESATLM4.min.js";var Zo=12345.78;export{U as AppLogTB,V as AppLogTBC,D as ApplogStream,to as ApplogStreamInMemory,Mo as ApplogStreamTB,Vo as BOOL,Ro as Bool,R as CIDTB,Xo as DefaultFalse,Wo as DefaultTrue,Q as EntityID,P as EntityID_LENGTH,E as MappedApplogStream,Uo as NUM,O as Nullable,Oo as Num,Po as Obj,Qo as Opt,po as QueryNode,xo as QueryNodes,So as STR,No as Str,S as URL,eo as WriteableApplogStream,T as actualize,Co as agentsOfStream,q as applogStreamComparer,x as areApplogsEqual,a as arrStats,g as arraysContainSameElements,N as assertOnlyCurrent,M as assertRaw,Yo as checkParityTB,r as compareApplogsByTs,z as computedFnDeepCompare,l as computedStructuralComparer,j as createDebugName,k as createDebugNameObj,d as cyrb53hash,h as dateNowIso,Bo as decodeCar,Ao as decodeCarToApplogs,_ as encodeApplog,Z as encodeApplogAndGetCid,oo as encodeBlock,ro as encodeBlockOriginal,To as entityOverlap,ao as entityOverlapCount,io as filterAndMap,W as getApplogTypeErrors,$ as getCidSync,m as getHashID,K as getUntrackedFilterResults,I as getUntrackedPattern,ko as hasAg,L as hasFilter,qo as hasPv,lo as hasTs,Lo as includedIn,Ko as includes,B as isInitEvent,Ho as isPublication,c as isStaticPattern,Io as isSubscription,t as isTsBefore,X as isValidApplog,n as isVariable,o as isoDateStrCompare,zo as joinStreams,Eo as makeCarBlob,Do as makeCarOut,J as makeFilter,bo as mapTo,w as matchPart,v as matchPartStatic,C as matchPattern,Fo as neverEncryptAttrs,y as observableArrayMap,jo as prefixAt,ho as prefixAttrs,Y as prepareForPub,Go as preparePubForPush,A as prettifyStreamName,no as query,vo as queryAndMap,Jo as queryDivergencesByPrev,wo as queryEntity,u as queryNodesComparer,co as queryNot,so as queryStep,f as removeDuplicateAppLogs,i as resolveOrRemoveVariables,H as rollingAcc,F as rollingFilter,G as rollingMapper,e as sortApplogsByTs,go as startsWith,b as tsNearlySame,p as uniqueEnFromAppLogs,s as variableNameWithoutQuestionmark,yo as withPv,uo as withTs,mo as withoutDeleted,fo as withoutHistory,Zo as wovinCoreTest};
1
+ import"./chunk-7IDQIMQO.min.js";import"./chunk-RPPZKO5L.min.js";import{a as Fo,b as Go,c as Ho,d as Io,e as Jo}from"./chunk-HNATM27J.min.js";import{a as Ao,b as Bo,c as Do,d as Eo}from"./chunk-NGPPHX5A.min.js";import{a as Ko,b as Lo,c as Mo}from"./chunk-LECZSORU.min.js";import{a as No,b as Oo,c as Po,d as Qo,e as Ro,f as So,g as Uo,h as Vo,i as Wo,j as Xo,k as Yo,l as Zo}from"./chunk-F3MRAJXL.min.js";import{A as bo,B as go,C as ho,D as jo,E as ko,F as lo,G as qo,H as uo,I as yo,J as zo,c as O,d as P,e as Q,f as R,g as S,h as U,i as V,j as W,k as X,l as eo,m as to,n as po,o as xo,p as fo,q as mo,r as no,s as so,t as co,u as io,v as vo,w as wo,x as Co,y as To,z as ao}from"./chunk-HHXZXKNM.min.js";import{A as a,B as b,C as d,D as g,E as h,F as j,G as k,H as l,I as q,J as u,K as y,L as z,M as A,N as B,O as D,P as E,Q as F,R as G,S as H,T as I,U as J,V as K,W as L,X as M,Y as N,k as o,l as r,m as e,n as t,o as p,p as x,q as f,r as m,s as n,t as s,u as c,v as i,w as v,x as w,y as C,z as T}from"./chunk-5R2ELTEJ.min.js";import{m as Y,n as Z,o as _,p as $,q as oo,r as ro}from"./chunk-KESATLM4.min.js";var _o=12345.78;export{U as AppLogTB,V as AppLogTBC,D as ApplogStream,to as ApplogStreamInMemory,No as ApplogStreamTB,Wo as BOOL,So as Bool,R as CIDTB,Yo as DefaultFalse,Xo as DefaultTrue,Q as EntityID,P as EntityID_LENGTH,E as MappedApplogStream,Vo as NUM,O as Nullable,Po as Num,Qo as Obj,Ro as Opt,po as QueryNode,xo as QueryNodes,Uo as STR,Oo as Str,S as URL,eo as WriteableApplogStream,T as actualize,Co as agentsOfStream,q as applogStreamComparer,x as areApplogsEqual,a as arrStats,g as arraysContainSameElements,N as assertOnlyCurrent,M as assertRaw,Zo as checkParityTB,r as compareApplogsByTs,z as computedFnDeepCompare,l as computedStructuralComparer,j as createDebugName,k as createDebugNameObj,d as cyrb53hash,h as dateNowIso,Bo as decodeCar,Ao as decodeCarToApplogs,_ as encodeApplog,Z as encodeApplogAndGetCid,Ho as encodeApplogsAsCar,oo as encodeBlock,ro as encodeBlockOriginal,To as entityOverlap,ao as entityOverlapCount,io as filterAndMap,W as getApplogTypeErrors,$ as getCidSync,m as getHashID,K as getUntrackedFilterResults,I as getUntrackedPattern,ko as hasAg,L as hasFilter,qo as hasPv,lo as hasTs,Mo as includedIn,Lo as includes,B as isInitEvent,Io as isPublication,c as isStaticPattern,Jo as isSubscription,t as isTsBefore,X as isValidApplog,n as isVariable,o as isoDateStrCompare,zo as joinStreams,Eo as makeCarBlob,Do as makeCarOut,J as makeFilter,bo as mapTo,w as matchPart,v as matchPartStatic,C as matchPattern,Fo as neverEncryptAttrs,y as observableArrayMap,jo as prefixAt,ho as prefixAttrs,Y as prepareForPub,Go as preparePubForPush,A as prettifyStreamName,no as query,vo as queryAndMap,Ko as queryDivergencesByPrev,wo as queryEntity,u as queryNodesComparer,co as queryNot,so as queryStep,f as removeDuplicateAppLogs,i as resolveOrRemoveVariables,H as rollingAcc,F as rollingFilter,G as rollingMapper,e as sortApplogsByTs,go as startsWith,b as tsNearlySame,p as uniqueEnFromAppLogs,s as variableNameWithoutQuestionmark,yo as withPv,uo as withTs,mo as withoutDeleted,fo as withoutHistory,_o as wovinCoreTest};
2
2
  //# sourceMappingURL=index.min.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export const wovinCoreTest = 12345.78\n\nexport * from './applog'\nexport * from './ipfs'\nexport * from './pubsub'\nexport * from './query'\nexport * from './stream'\nexport * from './types'\n// export * from './utils'\n"],"mappings":"6kCAAO,IAAMA,GAAgB","names":["wovinCoreTest"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export const wovinCoreTest = 12345.78\n\nexport * from './applog'\nexport * from './ipfs'\nexport * from './pubsub'\nexport * from './query'\nexport * from './stream'\nexport * from './types'\n// export * from './utils'\n"],"mappings":"qlCAAO,IAAMA,GAAgB","names":["wovinCoreTest"]}
@@ -1,6 +1,7 @@
1
- import { ApplogForInsert, EntityID } from '../applog/datom-types';
1
+ import { Applog, EntityID } from '../applog/datom-types';
2
2
  import { ApplogStream } from '../stream';
3
3
  import { IPublication } from './pubsub-types';
4
4
  export declare const neverEncryptAttrs: string[];
5
- export declare function preparePubForPush(agentHash: EntityID, agentFullID: string, publication: IPublication, dataStream: ApplogStream, applogs: ApplogForInsert[]): Promise<Blob>;
5
+ export declare function preparePubForPush(dataStream: ApplogStream, applogs: Applog[], agentHash: EntityID, agentFullID: string, publication: IPublication): Promise<Blob>;
6
+ export declare function encodeApplogsAsCar(applogs: Array<Applog | Uint8Array>): Promise<Blob>;
6
7
  //# sourceMappingURL=publication.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"publication.d.ts","sourceRoot":"","sources":["../../src/pubsub/publication.ts"],"names":[],"mappings":"AAGA,OAAO,EAAU,eAAe,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAGzE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAI7C,eAAO,MAAM,iBAAiB,UAK7B,CAAA;AAED,wBAAsB,iBAAiB,CACtC,SAAS,EAAE,QAAQ,EACnB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,YAAY,EACzB,UAAU,EAAE,YAAY,EACxB,OAAO,EAAE,eAAe,EAAE,iBAoF1B"}
1
+ {"version":3,"file":"publication.d.ts","sourceRoot":"","sources":["../../src/pubsub/publication.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAmB,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAGzE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAI7C,eAAO,MAAM,iBAAiB,UAK7B,CAAA;AAED,wBAAsB,iBAAiB,CACtC,UAAU,EAAE,YAAY,EACxB,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,EAAE,QAAQ,EACnB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,YAAY,iBA0EzB;AAED,wBAAsB,kBAAkB,CACvC,OAAO,EAAE,KAAK,CAAC,MAAM,GAAG,UAAU,CAAC,iBAenC"}
@@ -1,2 +1,2 @@
1
- import{a,b,c,d}from"./chunk-PL6CNZTW.min.js";import"./chunk-NGPPHX5A.min.js";import"./chunk-5R2ELTEJ.min.js";import"./chunk-KESATLM4.min.js";export{c as isPublication,d as isSubscription,a as neverEncryptAttrs,b as preparePubForPush};
1
+ import{a,b,c,d,e}from"./chunk-HNATM27J.min.js";import"./chunk-NGPPHX5A.min.js";import"./chunk-5R2ELTEJ.min.js";import"./chunk-KESATLM4.min.js";export{c as encodeApplogsAsCar,d as isPublication,e as isSubscription,a as neverEncryptAttrs,b as preparePubForPush};
2
2
  //# sourceMappingURL=pubsub.min.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wovin/core",
3
- "version": "0.0.2",
3
+ "version": "0.0.3-RC2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "rm -rf dist/ && concurrently \"pnpm build:code\" \"pnpm build:types\"",
@@ -1,2 +0,0 @@
1
- import{d as A}from"./chunk-NGPPHX5A.min.js";import{Q as f}from"./chunk-5R2ELTEJ.min.js";import{d as c,m as h,r as u}from"./chunk-KESATLM4.min.js";var{WARN:L,LOG:R,DEBUG:i,VERBOSE:E,ERROR:O}=c.setup(c.INFO),F=["agent/jwkd","agent/appAgent","pub/encryptedFor","pub/sharedKey"];async function T(t,I,P,K,o){let r=[],{sharedAgents:g,sharedKeyMap:s,sharedKey:p}=P??{},d=f(K,{en:t,at:["agent/ecdh","agent/jwkd","agent/appAgent"]});i("[publish] adding agent logs:",d),o.push(...d.applogs);let y,D=async(e,n)=>{throw new Error("todo: enc")};if(i("[publish] applogs ",o),g)if(!p||!s)i("weird state, publishing nonEncrypted",{sharedAgents:g,sharedKeyMap:s,sharedKey:p}),r=o;else{let e=[];for(let[n,b]of Array.from(s.entries()))e.push({ag:t,en:n,at:"pub/sharedKey",vl:b});for(let n of o){E("[crypto] encrypting ",n),F.includes(n.at)&&r.push(n);try{y=await D(n,p)}catch{}r.push(y)}}else r=o;r=r.map(e=>e.en?h(e):e);let a=await Promise.all(r.map(u));i("[publish] encoded root",{agentHash:t,agentFullID:I,encodedApplogs:a});let m=a.map(e=>e.cid??null),l=await u({applogs:m});return i("[publish] encoded root",{cids:m,encodedRoot:l}),await A(l.cid,[l,...a])}function j(t){return t?.pk!==void 0&&t?.lastPush!==void 0}function M(t){return t?.lastPull!==void 0}export{F as a,T as b,j as c,M as d};
2
- //# sourceMappingURL=chunk-PL6CNZTW.min.js.map
@@ -1 +0,0 @@
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 { ApplogStream } from '../stream'\nimport { rollingFilter } from '../stream/filters'\nimport { IPublication } from './pubsub-types'\n\nconst { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.INFO) // eslint-disable-line no-unused-vars\n\nexport 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\tagentHash: EntityID,\n\tagentFullID: string,\n\tpublication: IPublication,\n\tdataStream: ApplogStream,\n\tapplogs: ApplogForInsert[],\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\tlet maybeEncryptedApplogs: Array<Applog | ApplogForInsert | Uint8Array> = []\n\n\tconst { sharedAgents, sharedKeyMap, sharedKey } = publication ?? {}\n\tconst agentLogs = rollingFilter(dataStream, {\n\t\ten: agentHash,\n\t\tat: ['agent/ecdh', 'agent/jwkd', 'agent/appAgent'],\n\t})\n\tDEBUG(`[publish] adding agent logs:`, agentLogs)\n\tapplogs.push(...agentLogs.applogs)\n\tlet encPayload\n\tconst encryptAndTestDecrypt = async (applog: ApplogForInsert, keyToUse: CryptoKey) => {\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('[publish] applogs ', applogs)\n\n\tif (sharedAgents) { // encrypt all Applogs\n\t\tif (!sharedKey || !sharedKeyMap) {\n\t\t\tDEBUG('weird state, publishing nonEncrypted', { sharedAgents, sharedKeyMap, sharedKey }) // ? could this be a problem\n\t\t\tmaybeEncryptedApplogs = applogs\n\t\t} else {\n\t\t\tconst agentSharedKeyLogs = []\n\t\t\tfor (const [eachAgent, eachEncKey] of Array.from(sharedKeyMap.entries())) {\n\t\t\t\tagentSharedKeyLogs.push({\n\t\t\t\t\tag: agentHash,\n\t\t\t\t\ten: eachAgent,\n\t\t\t\t\tat: 'pub/sharedKey',\n\t\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\t})\n\t\t\t}\n\t\t\t// const encryptedForLogs = await insertApplogs(agentSharedKeyLogs)\n\t\t\t// DEBUG(`[publish] adding agentSharedKeyLogs:`, encryptedForLogs)\n\n\t\t\t// TODO ensure that all needed keys are in\n\t\t\tfor (const eachLog of applogs) {\n\t\t\t\tVERBOSE('[crypto] encrypting ', eachLog)\n\t\t\t\tif (neverEncryptAttrs.includes(eachLog.at)) {\n\t\t\t\t\tmaybeEncryptedApplogs.push(/* prepareForPub( */ eachLog /* ) */) // ? this seemed to double the below one - @gotjoshua?\n\n\t\t\t\t\t// continue\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tencPayload = await encryptAndTestDecrypt(eachLog, sharedKey)\n\t\t\t\t} catch (err) {\n\t\t\t\t\t// its already traced in encryptAndTestDecrypt\n\t\t\t\t\t// continue\n\t\t\t\t}\n\t\t\t\tmaybeEncryptedApplogs.push(encPayload)\n\t\t\t}\n\t\t}\n\t} else maybeEncryptedApplogs = applogs // publish nonEncrypted\n\n\tmaybeEncryptedApplogs = maybeEncryptedApplogs.map(log => (log as Applog).en ? prepareForPub(log as Applog) : log)\n\tconst encodedApplogs = await Promise.all(maybeEncryptedApplogs.map(encodeBlockOriginal))\n\tDEBUG('[publish] encoded root', { agentHash, agentFullID, encodedApplogs })\n\n\tconst cids = encodedApplogs.map(b => b.cid ?? null) // ? why would it be null\n\tconst root = { applogs: cids }\n\tconst encodedRoot = await encodeBlockOriginal(root)\n\tDEBUG('[publish] encoded root', { cids, encodedRoot })\n\n\tconst car = await makeCarBlob(encodedRoot.cid, [encodedRoot, ...encodedApplogs])\n\treturn car\n}\n","import { AgentID } from '../applog/datom-types'\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\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"],"mappings":"kJAUA,GAAM,CAAE,KAAAA,EAAM,IAAAC,EAAK,MAAAC,EAAO,QAAAC,EAAS,MAAAC,CAAM,EAAIC,EAAO,MAAMA,EAAO,IAAI,EAExDC,EAAoB,CAChC,aACA,iBACA,mBACA,eACD,EAEA,eAAsBC,EACrBC,EACAC,EACAC,EACAC,EACAC,EACC,CAKD,IAAIC,EAAsE,CAAC,EAErE,CAAE,aAAAC,EAAc,aA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OAAA7B,EAAM,yBAA0B,CAAE,KAAA6B,EAAM,YAAAE,CAAY,CAAC,EAEzC,MAAMC,EAAYD,EAAY,IAAK,CAACA,EAAa,GAAGJ,CAAc,CAAC,CAEhF,CCrEO,SAASM,EAAcC,EAA+B,CAC5D,OAAOA,GAAK,KAAO,QAAaA,GAAK,WAAa,MACnD,CACO,SAASC,EAAeD,EAAgC,CAC9D,OAAOA,GAAK,WAAa,MAC1B","names":["WARN","LOG","DEBUG","VERBOSE","ERROR","Logger","neverEncryptAttrs","preparePubForPush","agentHash","agentFullID","publication","dataStream","applogs","maybeEncryptedApplogs","sharedAgents","sharedKeyMap","sharedKey","agentLogs","rollingFilter","encPayload","encryptAndTestDecrypt","applog","keyToUse","agentSharedKeyLogs","eachAgent","eachEncKey","eachLog","log","prepareForPub","encodedApplogs","encodeBlockOriginal","cids","b","encodedRoot","makeCarBlob","isPublication","obj","isSubscription"]}