@xmtp/content-type-remote-attachment
Advanced tools
Comparing version 1.1.8 to 1.1.9
@@ -1,2 +0,2 @@ | ||
import{ContentTypeId as e,Ciphertext as t,decrypt as n,encrypt as r}from"@xmtp/xmtp-js";import*as o from"@noble/secp256k1";import{content as a}from"@xmtp/proto";const s=new e({authorityId:"xmtp.org",typeId:"attachment",versionMajor:1,versionMinor:0});class c{get contentType(){return s}encode(e){return{type:s,parameters:{filename:e.filename,mimeType:e.mimeType},content:e.data}}decode(e){return{filename:e.parameters.filename,mimeType:e.parameters.mimeType,data:e.content}}fallback(e){return`Can’t display "${e.filename}". This app doesn’t support attachments.`}shouldPush(){return!0}}const i=window.crypto,m=new e({authorityId:"xmtp.org",typeId:"remoteStaticAttachment",versionMajor:1,versionMinor:0});class d{static async load(r,s){const c=await fetch(r.url),m=new Uint8Array(await c.arrayBuffer());if(!m)throw new Error(`no payload for remote attachment at ${r.url}`);const d=new Uint8Array(await i.subtle.digest("SHA-256",m));if(o.utils.bytesToHex(d)!==r.contentDigest)throw new Error("content digest does not match");const p=new t({aes256GcmHkdfSha256:{hkdfSalt:r.salt,gcmNonce:r.nonce,payload:m}}),l=await n(p,r.secret),h=a.EncodedContent.decode(l);if(!h||!h.type)throw new Error("no encoded content");const y=h.type;if(!y)throw new Error("no content type");const u=s.codecFor(new e(y));if(!u)throw new Error(`no codec found for ${h.type?.typeId}`);return u.decode(h,s)}static async encodeEncrypted(e,t){const n=i.getRandomValues(new Uint8Array(32)),s=a.EncodedContent.encode(t.encode(e,{codecFor(){}})).finish(),c=await r(s,n),m=c.aes256GcmHkdfSha256?.hkdfSalt,d=c.aes256GcmHkdfSha256?.gcmNonce,p=c.aes256GcmHkdfSha256?.payload;if(!m||!d||!p)throw new Error("missing encryption key");const l=new Uint8Array(await i.subtle.digest("SHA-256",p));return{digest:o.utils.bytesToHex(l),secret:n,salt:m,nonce:d,payload:p}}get contentType(){return m}encode(e){if(!e.url.startsWith("https"))throw new Error("scheme must be https");return{type:m,parameters:{contentDigest:e.contentDigest,salt:o.utils.bytesToHex(e.salt),nonce:o.utils.bytesToHex(e.nonce),secret:o.utils.bytesToHex(e.secret),scheme:e.scheme,contentLength:String(e.contentLength),filename:e.filename},content:(new TextEncoder).encode(e.url)}}decode(e){return{url:(new TextDecoder).decode(e.content),contentDigest:e.parameters.contentDigest,salt:o.utils.hexToBytes(e.parameters.salt),nonce:o.utils.hexToBytes(e.parameters.nonce),secret:o.utils.hexToBytes(e.parameters.secret),scheme:e.parameters.scheme,contentLength:parseInt(e.parameters.contentLength,10),filename:e.parameters.filename}}fallback(e){return`Can’t display "${e.filename}". This app doesn’t support attachments.`}shouldPush(){return!0}}export{c as AttachmentCodec,s as ContentTypeAttachment,m as ContentTypeRemoteAttachment,d as RemoteAttachmentCodec}; | ||
import{ContentTypeId as e}from"@xmtp/content-type-primitives";import*as t from"@noble/secp256k1";import{content as n}from"@xmtp/proto";import{Ciphertext as r,decrypt as o,encrypt as a}from"@xmtp/xmtp-js";const s=new e({authorityId:"xmtp.org",typeId:"attachment",versionMajor:1,versionMinor:0});class c{get contentType(){return s}encode(e){return{type:s,parameters:{filename:e.filename,mimeType:e.mimeType},content:e.data}}decode(e){return{filename:e.parameters.filename,mimeType:e.parameters.mimeType,data:e.content}}fallback(e){return`Can’t display "${e.filename}". This app doesn’t support attachments.`}shouldPush(){return!0}}const i=window.crypto,m=new e({authorityId:"xmtp.org",typeId:"remoteStaticAttachment",versionMajor:1,versionMinor:0});class p{static async load(a,s){const c=await fetch(a.url),m=new Uint8Array(await c.arrayBuffer());if(!m)throw new Error(`no payload for remote attachment at ${a.url}`);const p=new Uint8Array(await i.subtle.digest("SHA-256",m));if(t.utils.bytesToHex(p)!==a.contentDigest)throw new Error("content digest does not match");const d=new r({aes256GcmHkdfSha256:{hkdfSalt:a.salt,gcmNonce:a.nonce,payload:m}}),l=await o(d,a.secret),h=n.EncodedContent.decode(l);if(!h||!h.type)throw new Error("no encoded content");const y=h.type;if(!y)throw new Error("no content type");const u=s.codecFor(new e(y));if(!u)throw new Error(`no codec found for ${h.type?.typeId}`);return u.decode(h,s)}static async encodeEncrypted(e,r){const o=i.getRandomValues(new Uint8Array(32)),s=n.EncodedContent.encode(r.encode(e,{codecFor(){}})).finish(),c=await a(s,o),m=c.aes256GcmHkdfSha256?.hkdfSalt,p=c.aes256GcmHkdfSha256?.gcmNonce,d=c.aes256GcmHkdfSha256?.payload;if(!m||!p||!d)throw new Error("missing encryption key");const l=new Uint8Array(await i.subtle.digest("SHA-256",d));return{digest:t.utils.bytesToHex(l),secret:o,salt:m,nonce:p,payload:d}}get contentType(){return m}encode(e){if(!e.url.startsWith("https"))throw new Error("scheme must be https");return{type:m,parameters:{contentDigest:e.contentDigest,salt:t.utils.bytesToHex(e.salt),nonce:t.utils.bytesToHex(e.nonce),secret:t.utils.bytesToHex(e.secret),scheme:e.scheme,contentLength:String(e.contentLength),filename:e.filename},content:(new TextEncoder).encode(e.url)}}decode(e){return{url:(new TextDecoder).decode(e.content),contentDigest:e.parameters.contentDigest,salt:t.utils.hexToBytes(e.parameters.salt),nonce:t.utils.hexToBytes(e.parameters.nonce),secret:t.utils.hexToBytes(e.parameters.secret),scheme:e.parameters.scheme,contentLength:parseInt(e.parameters.contentLength,10),filename:e.parameters.filename}}fallback(e){return`Can’t display "${e.filename}". This app doesn’t support attachments.`}shouldPush(){return!0}}export{c as AttachmentCodec,s as ContentTypeAttachment,m as ContentTypeRemoteAttachment,p as RemoteAttachmentCodec}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { ContentTypeId, ContentCodec, EncodedContent, CodecRegistry } from '@xmtp/xmtp-js'; | ||
import { ContentTypeId, ContentCodec, EncodedContent, CodecRegistry } from '@xmtp/content-type-primitives'; | ||
@@ -36,3 +36,3 @@ declare const ContentTypeAttachment: ContentTypeId; | ||
declare class RemoteAttachmentCodec implements ContentCodec<RemoteAttachment> { | ||
static load<T>(remoteAttachment: RemoteAttachment, codecRegistry: CodecRegistry): Promise<T>; | ||
static load<T>(remoteAttachment: RemoteAttachment, codecRegistry: CodecRegistry<T>): Promise<T>; | ||
static encodeEncrypted<T>(content: T, codec: ContentCodec<T>): Promise<EncryptedEncodedContent>; | ||
@@ -39,0 +39,0 @@ get contentType(): ContentTypeId; |
@@ -1,4 +0,5 @@ | ||
import { ContentTypeId, Ciphertext, decrypt, encrypt } from '@xmtp/xmtp-js'; | ||
import { ContentTypeId } from '@xmtp/content-type-primitives'; | ||
import * as secp from '@noble/secp256k1'; | ||
import { content } from '@xmtp/proto'; | ||
import { Ciphertext, decrypt, encrypt } from '@xmtp/xmtp-js'; | ||
import { webcrypto } from 'node:crypto'; | ||
@@ -81,3 +82,2 @@ | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return codec.decode(encodedContent, codecRegistry); | ||
@@ -84,0 +84,0 @@ } |
{ | ||
"name": "@xmtp/content-type-remote-attachment", | ||
"version": "1.1.8", | ||
"version": "1.1.9", | ||
"description": "An XMTP content type to support sending file attachments that are stored off network", | ||
@@ -21,3 +21,3 @@ "keywords": [ | ||
"type": "git", | ||
"url": "git@github.com:xmtp/xmtp-js-content-types.git", | ||
"url": "git+ssh://git@github.com/xmtp/xmtp-js-content-types.git", | ||
"directory": "packages/content-type-remote-attachment" | ||
@@ -72,6 +72,8 @@ }, | ||
"@noble/secp256k1": "^1.7.1", | ||
"@xmtp/proto": "^3.29.0", | ||
"@xmtp/xmtp-js": "^11.3.12" | ||
"@xmtp/content-type-primitives": "^1.0.1", | ||
"@xmtp/proto": "^3.61.1", | ||
"@xmtp/xmtp-js": "^11.6.3" | ||
}, | ||
"devDependencies": { | ||
"@ianvs/prettier-plugin-sort-imports": "^4.2.1", | ||
"@rollup/plugin-terser": "^0.4.4", | ||
@@ -81,2 +83,3 @@ "@rollup/plugin-typescript": "^11.1.6", | ||
"@xmtp/rollup-plugin-resolve-extensions": "^1.0.1", | ||
"@xmtp/xmtp-js": "^11.6.3", | ||
"buffer": "^6.0.3", | ||
@@ -97,5 +100,2 @@ "eslint": "^8.57.0", | ||
}, | ||
"peerDependencies": { | ||
"@xmtp/xmtp-js": "^11.1.1" | ||
}, | ||
"publishConfig": { | ||
@@ -102,0 +102,0 @@ "access": "public", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41010
20
+ Added@xmtp/content-type-primitives@1.0.3(transitive)
Updated@xmtp/proto@^3.61.1
Updated@xmtp/xmtp-js@^11.6.3