@@ -169,9 +169,9 @@ function checkKey(key) {
169169 throw new Error ( `bad key: ${ JSON . stringify ( key ) } ` ) ;
170170 }
171171}
172- async function createEntryFromFile ( filepath ) {
172+ async function createEntryFromFile ( filepath , multicode ) {
173173 const buffer = await Deno . readFile ( filepath ) ;
174- const key = createCID ( buffer ) ;
174+ const key = createCID ( buffer , multicode ) ;
175175 return [ key , buffer ] ;
176176}
177177function createCID ( data , multicode = multicodes . RAW ) {
@@ -260,7 +260,15 @@ var init_utils = __esm({
260260 init_database_sqlite ( ) ;
261261 backends = { fs : database_fs_exports , sqlite : database_sqlite_exports } ;
262262 multibase = base58btc ;
263- multicodes = { JSON : 512 , RAW : 0 } ;
263+ multicodes = {
264+ RAW : 0 ,
265+ JSON : 512 ,
266+ SHELTER_CONTRACT_MANIFEST : 5316096 ,
267+ SHELTER_CONTRACT_TEXT : 5316097 ,
268+ SHELTER_CONTRACT_DATA : 5316098 ,
269+ SHELTER_FILE_MANIFEST : 5316099 ,
270+ SHELTER_FILE_CHUNK : 5316100
271+ } ;
264272 multihasher = default3 . blake2b . blake2b256 ;
265273 readJsonFile = async ( file ) => {
266274 const contents = await Deno . readTextFile ( path . resolve ( String ( file ) ) ) ;
@@ -297,8 +305,25 @@ async function upload(args, internal = false) {
297305 throw new Error ( `missing files!` ) ;
298306 const uploaded = [ ] ;
299307 const uploaderFn = await isDir ( urlOrDirOrSqliteFile ) ? uploadEntryToDir : urlOrDirOrSqliteFile . endsWith ( ".db" ) ? uploadEntryToSQLite : uploadEntryToURL ;
300- for ( const filepath of files ) {
301- const entry = await createEntryFromFile ( filepath ) ;
308+ for ( const filepath_ of files ) {
309+ let type = multicodes . RAW ;
310+ let filepath = filepath_ ;
311+ if ( filepath_ [ 1 ] === "|" ) {
312+ switch ( filepath_ [ 0 ] ) {
313+ case "r" :
314+ break ;
315+ case "m" :
316+ type = multicodes . SHELTER_CONTRACT_MANIFEST ;
317+ break ;
318+ case "t" :
319+ type = multicodes . SHELTER_CONTRACT_TEXT ;
320+ break ;
321+ default :
322+ throw new Error ( "Unknown file type: " + filepath_ [ 0 ] ) ;
323+ }
324+ filepath = filepath_ . slice ( 2 ) ;
325+ }
326+ const entry = await createEntryFromFile ( filepath , type ) ;
302327 const destination = await uploaderFn ( entry , urlOrDirOrSqliteFile ) ;
303328 if ( ! internal ) {
304329 console . log ( colors . green ( "uploaded:" ) , destination ) ;
@@ -351,11 +376,11 @@ async function deploy(args) {
351376 const json = JSON . parse ( Deno . readTextFileSync ( manifestPath ) ) ;
352377 const body = JSON . parse ( json . body ) ;
353378 const dirname = path . dirname ( manifestPath ) ;
354- toUpload . push ( path . join ( dirname , body . contract . file ) ) ;
379+ toUpload . push ( "t|" + path . join ( dirname , body . contract . file ) ) ;
355380 if ( body . contractSlim ) {
356- toUpload . push ( path . join ( dirname , body . contractSlim . file ) ) ;
381+ toUpload . push ( "t|" + path . join ( dirname , body . contractSlim . file ) ) ;
357382 }
358- toUpload . push ( manifestPath ) ;
383+ toUpload . push ( "m|" + manifestPath ) ;
359384 }
360385 await upload ( [ urlOrDirOrSqliteFile , ...toUpload ] , true ) ;
361386}
@@ -458,13 +483,13 @@ async function get(args) {
458483
459484// src/hash.ts
460485init_utils ( ) ;
461- async function hash ( args , internal = false ) {
486+ async function hash ( args , multicode = multicodes . RAW , internal = false ) {
462487 const [ filename ] = args ;
463488 if ( ! filename ) {
464489 console . error ( "please pass in a file" ) ;
465490 Deno . exit ( 1 ) ;
466491 }
467- const [ cid ] = await createEntryFromFile ( filename ) ;
492+ const [ cid ] = await createEntryFromFile ( filename , multicode ) ;
468493 if ( ! internal ) {
469494 console . log ( `CID(${ filename } ):` , cid ) ;
470495 }
@@ -787,15 +812,15 @@ async function manifest(args) {
787812 name,
788813 version : version2 ,
789814 contract : {
790- hash : await hash ( [ contractFile ] , true ) ,
815+ hash : await hash ( [ contractFile ] , multicodes . SHELTER_CONTRACT_TEXT , true ) ,
791816 file : contractBasename
792817 } ,
793818 signingKeys : publicKeys
794819 } ;
795820 if ( slim ) {
796821 body . contractSlim = {
797822 file : path . basename ( slim ) ,
798- hash : await hash ( [ slim ] , true )
823+ hash : await hash ( [ slim ] , multicodes . SHELTER_CONTRACT_TEXT , true )
799824 } ;
800825 }
801826 const serializedBody = JSON . stringify ( body ) ;
@@ -920,12 +945,12 @@ var verifySignature2 = async (args, internal = false) => {
920945 if ( ! body . contract ?. file ) {
921946 exit ( "Invalid manifest: no contract file" , internal ) ;
922947 }
923- const computedHash = await hash ( [ path . join ( parsedFilepath . dir , body . contract . file ) ] , true ) ;
948+ const computedHash = await hash ( [ path . join ( parsedFilepath . dir , body . contract . file ) ] , multicodes . SHELTER_CONTRACT_TEXT , true ) ;
924949 if ( computedHash !== body . contract . hash ) {
925950 exit ( `Invalid contract file hash. Expected ${ body . contract . hash } but got ${ computedHash } ` , internal ) ;
926951 }
927952 if ( body . contractSlim ) {
928- const computedHash2 = await hash ( [ path . join ( parsedFilepath . dir , body . contractSlim . file ) ] , true ) ;
953+ const computedHash2 = await hash ( [ path . join ( parsedFilepath . dir , body . contractSlim . file ) ] , multicodes . SHELTER_CONTRACT_TEXT , true ) ;
929954 if ( computedHash2 !== body . contractSlim . hash ) {
930955 exit ( `Invalid slim contract file hash. Expected ${ body . contractSlim . hash } but got ${ computedHash2 } ` , internal ) ;
931956 }
0 commit comments