├── envelope-cli ├── test │ ├── parm.txt │ ├── diag.txt │ ├── envelope.txt │ ├── ioplay.js │ ├── bytewords-creator.js │ └── crc32.js ├── package.json └── envelope-cli.js ├── .gitignore ├── README.md ├── .gitattributes ├── gordian-envelope.js.sln └── LICENSE /envelope-cli/test/parm.txt: -------------------------------------------------------------------------------- 1 | hi -------------------------------------------------------------------------------- /envelope-cli/test/diag.txt: -------------------------------------------------------------------------------- 1 | { 2 | "hi" : 5.78 3 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vs 2 | node_modules 3 | package-lock.json 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gordian-envelope.js 2 | Experimental code 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Disable LF normalization for all files 2 | * -text -------------------------------------------------------------------------------- /envelope-cli/test/envelope.txt: -------------------------------------------------------------------------------- 1 | ur:envelope/lftpcsihfpjziniaihoytpcsihjejtjlktjktpcsiafwjliddssngwct -------------------------------------------------------------------------------- /envelope-cli/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module", 3 | "devDependencies": { 4 | "eslint": "^8.53.0" 5 | }, 6 | "dependencies": { 7 | "cbor-object": "^1.0.3" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /envelope-cli/test/ioplay.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | const args = process.argv.slice(2); 3 | 4 | 5 | if (args.length == 0) { 6 | console.log("no params!"); 7 | process.exit(3); 8 | } 9 | 10 | let parm1 = args[0]; 11 | let parm2; 12 | if (args.length == 2) { 13 | parm2 = args[1]; 14 | } else { 15 | if (process.stdin.isTTY) { 16 | console.log("missing argument"); 17 | process.exit(3); 18 | } 19 | parm2 = fs.readFileSync(process.stdin.fd, "utf-8"); 20 | } 21 | console.log("parm1=" + parm1 + ", parm2=" + parm2); 22 | -------------------------------------------------------------------------------- /gordian-envelope.js.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.34221.43 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "envelope-cli", "envelope-cli", "{2C539431-D804-4478-8943-0E7672B837A7}" 7 | ProjectSection(SolutionItems) = preProject 8 | envelope-cli\package.json = envelope-cli\package.json 9 | envelope-cli\envelope-cli.js = envelope-cli\envelope-cli.js 10 | EndProjectSection 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D32D922C-51BA-4A8B-9E76-C6BD3F22A98D}" 13 | ProjectSection(SolutionItems) = preProject 14 | envelope-cli\test\bytewords-creator.js = envelope-cli\test\bytewords-creator.js 15 | envelope-cli\test\crc32.js = envelope-cli\test\crc32.js 16 | envelope-cli\test\diag.txt = envelope-cli\test\diag.txt 17 | envelope-cli\test\envelope.txt = envelope-cli\test\envelope.txt 18 | envelope-cli\test\ioplay.js = envelope-cli\test\ioplay.js 19 | envelope-cli\test\parm.txt = envelope-cli\test\parm.txt 20 | EndProjectSection 21 | EndProject 22 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Global files", "Global files", "{34754FB6-B496-46A4-A832-F9A6BB406C62}" 23 | ProjectSection(SolutionItems) = preProject 24 | .gitattributes = .gitattributes 25 | .gitignore = .gitignore 26 | EndProjectSection 27 | EndProject 28 | Global 29 | GlobalSection(SolutionProperties) = preSolution 30 | HideSolutionNode = FALSE 31 | EndGlobalSection 32 | GlobalSection(NestedProjects) = preSolution 33 | {D32D922C-51BA-4A8B-9E76-C6BD3F22A98D} = {2C539431-D804-4478-8943-0E7672B837A7} 34 | EndGlobalSection 35 | GlobalSection(ExtensibilityGlobals) = postSolution 36 | SolutionGuid = {CA47867D-F331-49B8-B25E-F6DF9AF083DF} 37 | EndGlobalSection 38 | EndGlobal 39 | -------------------------------------------------------------------------------- /envelope-cli/test/bytewords-creator.js: -------------------------------------------------------------------------------- 1 | // Program to create ByteWords tables 2 | 3 | const BYTEWORDS = "\ 4 | ableacidalsoapexaquaarchatomauntawayaxisbackbaldbarnbeltbetabias\ 5 | bluebodybragbrewbulbbuzzcalmcashcatschefcityclawcodecolacookcost\ 6 | cruxcurlcuspcyandarkdatadaysdelidicedietdoordowndrawdropdrumdull\ 7 | dutyeacheasyechoedgeepicevenexamexiteyesfactfairfernfigsfilmfish\ 8 | fizzflapflewfluxfoxyfreefrogfuelfundgalagamegeargemsgiftgirlglow\ 9 | goodgraygrimgurugushgyrohalfhanghardhawkheathelphighhillholyhope\ 10 | hornhutsicedideaidleinchinkyintoirisironitemjadejazzjoinjoltjowl\ 11 | judojugsjumpjunkjurykeepkenokeptkeyskickkilnkingkitekiwiknoblamb\ 12 | lavalazyleaflegsliarlimplionlistlogoloudloveluaulucklungmainmany\ 13 | mathmazememomenumeowmildmintmissmonknailnavyneednewsnextnoonnote\ 14 | numbobeyoboeomitonyxopenovalowlspaidpartpeckplaypluspoempoolpose\ 15 | puffpumapurrquadquizraceramprealredorichroadrockroofrubyruinruns\ 16 | rustsafesagascarsetssilkskewslotsoapsolosongstubsurfswantacotask\ 17 | taxitenttiedtimetinytoiltombtoystriptunatwinuglyundouniturgeuser\ 18 | vastveryvetovialvibeviewvisavoidvowswallwandwarmwaspwavewaxywebs\ 19 | whatwhenwhizwolfworkyankyawnyellyogayurtzapszerozestzinczonezoom"; 20 | 21 | let bytewords = "const TO_BYTEWORDS = ["; 22 | for (let q = 0; q < BYTEWORDS.length; q += 4) { 23 | if (q) { 24 | bytewords += ","; 25 | } 26 | if (q % 64 == 0) { 27 | bytewords += "\n "; 28 | } else { 29 | bytewords += " "; 30 | } 31 | bytewords += "'" + BYTEWORDS[q] + BYTEWORDS[q + 3] + "'"; 32 | } 33 | bytewords += "];\n\n"; 34 | 35 | let g = eval(bytewords + "TO_BYTEWORDS;"); 36 | bytewords += "const FROM_BYTEWORDS = ["; 37 | for (let q = 0; q < 26*26; q++) { 38 | let entry = " -1" 39 | let search = String.fromCharCode(Number.parseInt(q / 26) + 0x61) + String.fromCharCode(Number.parseInt(q % 26) + 0x61); 40 | for (let i = 0; i < g.length; i++) { 41 | if (g[i] == search) { 42 | entry = i.toString(16); 43 | if (entry.length == 1) entry = "0" + entry; 44 | entry = "0x" + entry; 45 | break; 46 | } 47 | }; 48 | if (q) { 49 | bytewords += ","; 50 | } 51 | if (q % 16 == 0) { 52 | bytewords += "\n "; 53 | } else { 54 | bytewords += " "; 55 | } 56 | bytewords += entry; 57 | } 58 | bytewords += "];\n\n"; 59 | 60 | console.log(bytewords); 61 | 62 | 63 | -------------------------------------------------------------------------------- /envelope-cli/test/crc32.js: -------------------------------------------------------------------------------- 1 | // CRC32 code and table generator 2 | import CBOR from 'cbor-object'; 3 | // Gordian Envelope CLI 4 | 5 | var a_table = "00000000 77073096 ee0e612c 990951ba 076dc419 706af48f e963a535 9e6495a3 0edb8832 79dcb8a4 e0d5e91e 97d2d988 09b64c2b 7eb17cbd e7b82d07 90bf1d91 1db71064 6ab020f2 f3b97148 84be41de 1adad47d 6ddde4eb f4d4b551 83d385c7 136c9856 646ba8c0 fd62f97a 8a65c9ec 14015c4f 63066cd9 fa0f3d63 8d080df5 3b6e20c8 4c69105e d56041e4 a2677172 3c03e4d1 4b04d447 d20d85fd a50ab56b 35b5a8fa 42b2986c dbbbc9d6 acbcf940 32d86ce3 45df5c75 dcd60dcf abd13d59 26d930ac 51de003a c8d75180 bfd06116 21b4f4b5 56b3c423 cfba9599 b8bda50f 2802b89e 5f058808 c60cd9b2 b10be924 2f6f7c87 58684c11 c1611dab b6662d3d 76dc4190 01db7106 98d220bc efd5102a 71b18589 06b6b51f 9fbfe4a5 e8b8d433 7807c9a2 0f00f934 9609a88e e10e9818 7f6a0dbb 086d3d2d 91646c97 e6635c01 6b6b51f4 1c6c6162 856530d8 f262004e 6c0695ed 1b01a57b 8208f4c1 f50fc457 65b0d9c6 12b7e950 8bbeb8ea fcb9887c 62dd1ddf 15da2d49 8cd37cf3 fbd44c65 4db26158 3ab551ce a3bc0074 d4bb30e2 4adfa541 3dd895d7 a4d1c46d d3d6f4fb 4369e96a 346ed9fc ad678846 da60b8d0 44042d73 33031de5 aa0a4c5f dd0d7cc9 5005713c 270241aa be0b1010 c90c2086 5768b525 206f85b3 b966d409 ce61e49f 5edef90e 29d9c998 b0d09822 c7d7a8b4 59b33d17 2eb40d81 b7bd5c3b c0ba6cad edb88320 9abfb3b6 03b6e20c 74b1d29a ead54739 9dd277af 04db2615 73dc1683 e3630b12 94643b84 0d6d6a3e 7a6a5aa8 e40ecf0b 9309ff9d 0a00ae27 7d079eb1 f00f9344 8708a3d2 1e01f268 6906c2fe f762575d 806567cb 196c3671 6e6b06e7 fed41b76 89d32be0 10da7a5a 67dd4acc f9b9df6f 8ebeeff9 17b7be43 60b08ed5 d6d6a3e8 a1d1937e 38d8c2c4 4fdff252 d1bb67f1 a6bc5767 3fb506dd 48b2364b d80d2bda af0a1b4c 36034af6 41047a60 df60efc3 a867df55 316e8eef 4669be79 cb61b38c bc66831a 256fd2a0 5268e236 cc0c7795 bb0b4703 220216b9 5505262f c5ba3bbe b2bd0b28 2bb45a92 5cb36a04 c2d7ffa7 b5d0cf31 2cd99e8b 5bdeae1d 9b64c2b0 ec63f226 756aa39c 026d930a 9c0906a9 eb0e363f 72076785 05005713 95bf4a82 e2b87a14 7bb12bae 0cb61b38 92d28e9b e5d5be0d 7cdcefb7 0bdbdf21 86d3d2d4 f1d4e242 68ddb3f8 1fda836e 81be16cd f6b9265b 6fb077e1 18b74777 88085ae6 ff0f6a70 66063bca 11010b5c 8f659eff f862ae69 616bffd3 166ccf45 a00ae278 d70dd2ee 4e048354 3903b3c2 a7672661 d06016f7 4969474d 3e6e77db aed16a4a d9d65adc 40df0b66 37d83bf0 a9bcae53 debb9ec5 47b2cf7f 30b5ffe9 bdbdf21c cabac28a 53b39330 24b4a3a6 bad03605 cdd70693 54de5729 23d967bf b3667a2e c4614ab8 5d681b02 2a6f2b94 b40bbe37 c30c8ea1 5a05df1b 2d02ef8d"; 6 | var b_table = a_table.split(' ').map(function(s){ return parseInt(s,16) }); 7 | function s_crc32 (str) { 8 | var crc = -1; 9 | for(var i=0, iTop=str.length; i>> 8 ) ^ b_table[( crc ^ str.charCodeAt( i ) ) & 0xFF]; 11 | } 12 | return (crc ^ (-1)) >>> 0; 13 | } 14 | 15 | function b_crc32 (byteArray) { 16 | var crc = -1; 17 | for(var i=0, iTop=byteArray.length; i>> 8 ) ^ b_table[( crc ^ byteArray[i]) & 0xFF]; 19 | } 20 | return (crc ^ (-1)) >>> 0; 21 | } 22 | 23 | const CRC32_TABLE = [ 24 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 25 | 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 26 | 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 27 | 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 28 | 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 29 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 30 | 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 31 | 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 32 | 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 33 | 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 34 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 35 | 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 36 | 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 37 | 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 38 | 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 39 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 40 | 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 41 | 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 42 | 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 43 | 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 44 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 45 | 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 46 | 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 47 | 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 48 | 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 49 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 50 | 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 51 | 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 52 | 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 53 | 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 54 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 55 | 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d]; 56 | 57 | function crc32 (byteArray) { 58 | let crc = -1; 59 | byteArray.forEach(byte => { 60 | crc = (crc >>> 8) ^ CRC32_TABLE[(crc ^ byte) & 0xff]; 61 | }); 62 | crc ^= 0xffffffff; 63 | let result = new Uint8Array(4); 64 | for (let i = 3; i >= 0; i--) { 65 | result[i] = crc; 66 | crc >>>= 8; 67 | } 68 | console.log("HEX=" + CBOR.toHex(result)); 69 | return result; 70 | } 71 | 72 | let byteArray = CBOR.fromHex("d9012ca20150c7098580125e2ab0981253468b2dbc5202d8641947da"); 73 | console.log(b_crc32(byteArray)); 74 | console.log(crc32(byteArray)); 75 | console.log(b_crc32(new Uint8Array([0]))); 76 | 77 | -------------------------------------------------------------------------------- /envelope-cli/envelope-cli.js: -------------------------------------------------------------------------------- 1 | // Gordian Envelope CLI 2 | import CBOR from 'cbor-object'; 3 | import Crypto from 'node:crypto'; 4 | import fs from 'fs'; 5 | 6 | const ENVELOPE_TAG = 200n; 7 | const SUBJECT_TAG = 24n; 8 | const DATE_TAG = 0n; 9 | const URI_TAG = 32n; 10 | 11 | const ENVELOPE_UR = "ur:envelope/"; 12 | 13 | const TO_BYTEWORDS = [ 14 | 'ae', 'ad', 'ao', 'ax', 'aa', 'ah', 'am', 'at', 'ay', 'as', 'bk', 'bd', 'bn', 'bt', 'ba', 'bs', 15 | 'be', 'by', 'bg', 'bw', 'bb', 'bz', 'cm', 'ch', 'cs', 'cf', 'cy', 'cw', 'ce', 'ca', 'ck', 'ct', 16 | 'cx', 'cl', 'cp', 'cn', 'dk', 'da', 'ds', 'di', 'de', 'dt', 'dr', 'dn', 'dw', 'dp', 'dm', 'dl', 17 | 'dy', 'eh', 'ey', 'eo', 'ee', 'ec', 'en', 'em', 'et', 'es', 'ft', 'fr', 'fn', 'fs', 'fm', 'fh', 18 | 'fz', 'fp', 'fw', 'fx', 'fy', 'fe', 'fg', 'fl', 'fd', 'ga', 'ge', 'gr', 'gs', 'gt', 'gl', 'gw', 19 | 'gd', 'gy', 'gm', 'gu', 'gh', 'go', 'hf', 'hg', 'hd', 'hk', 'ht', 'hp', 'hh', 'hl', 'hy', 'he', 20 | 'hn', 'hs', 'id', 'ia', 'ie', 'ih', 'iy', 'io', 'is', 'in', 'im', 'je', 'jz', 'jn', 'jt', 'jl', 21 | 'jo', 'js', 'jp', 'jk', 'jy', 'kp', 'ko', 'kt', 'ks', 'kk', 'kn', 'kg', 'ke', 'ki', 'kb', 'lb', 22 | 'la', 'ly', 'lf', 'ls', 'lr', 'lp', 'ln', 'lt', 'lo', 'ld', 'le', 'lu', 'lk', 'lg', 'mn', 'my', 23 | 'mh', 'me', 'mo', 'mu', 'mw', 'md', 'mt', 'ms', 'mk', 'nl', 'ny', 'nd', 'ns', 'nt', 'nn', 'ne', 24 | 'nb', 'oy', 'oe', 'ot', 'ox', 'on', 'ol', 'os', 'pd', 'pt', 'pk', 'py', 'ps', 'pm', 'pl', 'pe', 25 | 'pf', 'pa', 'pr', 'qd', 'qz', 're', 'rp', 'rl', 'ro', 'rh', 'rd', 'rk', 'rf', 'ry', 'rn', 'rs', 26 | 'rt', 'se', 'sa', 'sr', 'ss', 'sk', 'sw', 'st', 'sp', 'so', 'sg', 'sb', 'sf', 'sn', 'to', 'tk', 27 | 'ti', 'tt', 'td', 'te', 'ty', 'tl', 'tb', 'ts', 'tp', 'ta', 'tn', 'uy', 'uo', 'ut', 'ue', 'ur', 28 | 'vt', 'vy', 'vo', 'vl', 've', 'vw', 'va', 'vd', 'vs', 'wl', 'wd', 'wm', 'wp', 'we', 'wy', 'ws', 29 | 'wt', 'wn', 'wz', 'wf', 'wk', 'yk', 'yn', 'yl', 'ya', 'yt', 'zs', 'zo', 'zt', 'zc', 'ze', 'zm']; 30 | 31 | const FROM_BYTEWORDS = [ 32 | 0x04, -1, -1, 0x01, 0x00, -1, -1, 0x05, -1, -1, -1, -1, 0x06, -1, 0x02, -1, 33 | -1, -1, 0x09, 0x07, -1, -1, -1, 0x03, 0x08, -1, 0x0e, 0x14, -1, 0x0b, 0x10, -1, 34 | 0x12, -1, -1, -1, 0x0a, -1, -1, 0x0c, -1, -1, -1, -1, 0x0f, 0x0d, -1, -1, 35 | 0x13, -1, 0x11, 0x15, 0x1d, -1, -1, -1, 0x1c, 0x19, -1, 0x17, -1, -1, 0x1e, 0x21, 36 | 0x16, 0x23, -1, 0x22, -1, -1, 0x18, 0x1f, -1, -1, 0x1b, 0x20, 0x1a, -1, 0x25, -1, 37 | -1, -1, 0x28, -1, -1, -1, 0x27, -1, 0x24, 0x2f, 0x2e, 0x2b, -1, 0x2d, -1, 0x2a, 38 | 0x26, 0x29, -1, -1, 0x2c, -1, 0x30, -1, -1, -1, 0x35, -1, 0x34, -1, -1, 0x31, 39 | -1, -1, -1, -1, 0x37, 0x36, 0x33, -1, -1, -1, 0x39, 0x38, -1, -1, -1, -1, 40 | 0x32, -1, -1, -1, -1, 0x48, 0x45, -1, 0x46, 0x3f, -1, -1, -1, 0x47, 0x3e, 0x3c, 41 | -1, 0x41, -1, 0x3b, 0x3d, 0x3a, -1, -1, 0x42, 0x43, 0x44, 0x40, 0x49, -1, -1, 0x50, 42 | 0x4a, -1, -1, 0x54, -1, -1, -1, 0x4e, 0x52, -1, 0x55, -1, -1, 0x4b, 0x4c, 0x4d, 43 | 0x53, -1, 0x4f, -1, 0x51, -1, -1, -1, -1, 0x58, 0x5f, 0x56, 0x57, 0x5c, -1, -1, 44 | 0x59, 0x5d, -1, 0x60, -1, 0x5b, -1, -1, 0x61, 0x5a, -1, -1, -1, -1, 0x5e, -1, 45 | 0x63, -1, -1, 0x62, 0x64, -1, -1, 0x65, -1, -1, -1, -1, 0x6a, 0x69, 0x67, -1, 46 | -1, -1, 0x68, -1, -1, -1, -1, -1, 0x66, -1, -1, -1, -1, -1, 0x6b, -1, 47 | -1, -1, -1, -1, 0x73, 0x6f, -1, 0x6d, 0x70, 0x72, -1, -1, 0x71, 0x6e, -1, -1, 48 | -1, -1, 0x74, 0x6c, -1, 0x7e, -1, -1, 0x7c, -1, 0x7b, -1, 0x7d, -1, 0x79, -1, 49 | -1, 0x7a, 0x76, 0x75, -1, -1, 0x78, 0x77, -1, -1, -1, -1, -1, -1, 0x80, 0x7f, 50 | -1, 0x89, 0x8a, 0x82, 0x8d, -1, -1, -1, 0x8c, -1, -1, 0x86, 0x88, 0x85, -1, 0x84, 51 | 0x83, 0x87, 0x8b, -1, -1, -1, 0x81, -1, -1, -1, -1, 0x95, 0x91, -1, -1, 0x90, 52 | -1, -1, 0x98, -1, -1, 0x8e, 0x92, -1, -1, -1, 0x97, 0x96, 0x93, -1, 0x94, -1, 53 | 0x8f, -1, -1, 0xa0, -1, 0x9b, 0x9f, -1, -1, -1, -1, -1, -1, 0x99, -1, 0x9e, 54 | -1, -1, -1, -1, 0x9c, 0x9d, -1, -1, -1, -1, 0x9a, -1, -1, -1, -1, -1, 55 | 0xa2, -1, -1, -1, -1, -1, -1, 0xa6, -1, 0xa5, -1, -1, -1, -1, 0xa7, 0xa3, 56 | -1, -1, -1, 0xa4, 0xa1, -1, 0xb1, -1, -1, 0xa8, 0xaf, 0xb0, -1, -1, -1, -1, 57 | 0xaa, 0xae, 0xad, -1, -1, -1, -1, 0xb2, 0xac, 0xa9, -1, -1, -1, -1, 0xab, -1, 58 | -1, -1, -1, 0xb3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 59 | -1, -1, -1, -1, -1, -1, -1, -1, -1, 0xb4, -1, -1, -1, 0xba, 0xb5, 0xbc, 60 | -1, 0xb9, -1, -1, 0xbb, 0xb7, -1, 0xbe, 0xb8, 0xb6, -1, -1, 0xbf, 0xc0, -1, -1, 61 | -1, -1, 0xbd, -1, 0xc2, 0xcb, -1, -1, 0xc1, 0xcc, 0xca, -1, -1, -1, 0xc5, -1, 62 | -1, 0xcd, 0xc9, 0xc8, -1, 0xc3, 0xc4, 0xc7, -1, -1, 0xc6, -1, -1, -1, 0xd9, 0xd6, 63 | -1, 0xd2, 0xd3, -1, -1, -1, 0xd0, -1, 0xcf, 0xd5, -1, 0xda, 0xce, 0xd8, -1, -1, 64 | 0xd7, 0xd1, -1, -1, -1, -1, 0xd4, -1, -1, -1, -1, -1, 0xde, -1, -1, -1, 65 | -1, -1, -1, -1, -1, -1, 0xdc, -1, -1, 0xdf, -1, 0xdd, -1, -1, -1, -1, 66 | 0xdb, -1, 0xe6, -1, -1, 0xe7, 0xe4, -1, -1, -1, -1, -1, -1, 0xe3, -1, -1, 67 | 0xe2, -1, -1, -1, 0xe8, 0xe0, -1, -1, 0xe5, -1, 0xe1, -1, -1, -1, -1, 0xea, 68 | 0xed, 0xf3, -1, -1, -1, -1, 0xf4, 0xe9, 0xeb, 0xf1, -1, 0xec, -1, -1, 0xef, 0xf0, 69 | -1, -1, -1, -1, 0xee, 0xf2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 70 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 71 | 0xf8, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0xf5, 0xf7, -1, 0xf6, -1, -1, 72 | -1, -1, -1, 0xf9, -1, -1, -1, -1, -1, -1, -1, -1, 0xfd, -1, 0xfe, -1, 73 | -1, -1, -1, -1, -1, -1, 0xff, -1, 0xfb, -1, -1, -1, 0xfa, 0xfc, -1, -1, 74 | -1, -1, -1, -1]; 75 | 76 | const CRC32_TABLE = [ 77 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 78 | 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 79 | 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 80 | 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 81 | 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 82 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 83 | 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 84 | 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 85 | 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 86 | 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 87 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 88 | 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 89 | 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 90 | 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 91 | 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 92 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 93 | 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 94 | 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 95 | 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 96 | 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 97 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 98 | 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 99 | 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 100 | 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 101 | 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 102 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 103 | 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 104 | 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 105 | 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 106 | 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 107 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 108 | 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d]; 109 | 110 | const args = process.argv.slice(2); 111 | 112 | function fatal(message) { 113 | console.log("Error: " + message); 114 | process.exit(3); 115 | } 116 | 117 | function getLastArgument(index) { 118 | if (args.length > index + 1) fatal("unexpected argument: " + args[index + 1]); 119 | if (args.length == index) { 120 | if (process.stdin.isTTY) getArgument(index); 121 | return fs.readFileSync(process.stdin.fd, "utf-8").trim(); 122 | } else { 123 | return args[index].trim(); 124 | } 125 | } 126 | 127 | function getArgument(index) { 128 | if (index >= args.length) fatal("missing argument"); 129 | return args[index].trim(); 130 | } 131 | 132 | function strip(arg, argEqual) { 133 | if (arg.length <= argEqual.length || arg.substring(0, argEqual.length) != argEqual) { 134 | fatal("expected '" + argEqual + "argument'"); 135 | } 136 | return arg.substring(argEqual.length); 137 | } 138 | 139 | function byteWordsEncode(byteArray) { 140 | // console.log(CBOR.toHex(byteArray)); 141 | byteArray = CBOR.addArrays(byteArray, crc32(byteArray)); 142 | let byteWords = ""; 143 | byteArray.forEach(byte => { 144 | byteWords += TO_BYTEWORDS[byte]; 145 | }); 146 | return byteWords; 147 | } 148 | 149 | function convertToNum(byteWords, index) { 150 | return byteWords.charCodeAt(index) - 0x61; 151 | } 152 | 153 | function byteWordsDecode(byteWords) { 154 | let length = byteWords.length; 155 | if (length <= 8) fatal("missing ByteWord checksum"); 156 | if (length & 1) fatal("uneven number of ByteWord characters"); 157 | if (!byteWords.match(/^[a-z]+?$/)) fatal("invalid ByteWord characters"); 158 | let bytes = new Uint8Array(length >> 1); 159 | for (let i = 0, q = 0; q < length;) { 160 | let byte = FROM_BYTEWORDS[(convertToNum(byteWords, q++) * 26) + convertToNum(byteWords, q++)]; 161 | if (byte < 0) fatal("invalid ByteWord"); 162 | bytes[i++] = byte; 163 | } 164 | let result = bytes.subarray(0, bytes.length - 4); 165 | if (CBOR.compareArrays(crc32(result), bytes.subarray(result.length))) fatal("crc32 mismatch"); 166 | // console.log(CBOR.toHex(result)); 167 | return result; 168 | } 169 | 170 | function crc32 (byteArray) { 171 | let crc = -1; 172 | byteArray.forEach(byte => { 173 | crc = (crc >>> 8) ^ CRC32_TABLE[(crc ^ byte) & 0xff]; 174 | }); 175 | crc ^= 0xffffffff; 176 | let result = new Uint8Array(4); 177 | for (let i = 3; i >= 0; i--) { 178 | result[i] = crc; 179 | crc >>>= 8; 180 | } 181 | return result; 182 | } 183 | 184 | function getEnvelope(atIndex) { 185 | return CBOR.Tag(ENVELOPE_TAG, 186 | CBOR.decode(byteWordsDecode(strip(getLastArgument(atIndex), "ur:envelope/")))); 187 | } 188 | 189 | function subjectCommand() { 190 | if (getArgument(1) != "type") fatal("missing \"type\" argument"); 191 | let type = getArgument(2); 192 | let argument = getLastArgument(3); 193 | let cborObject; 194 | switch (type) { 195 | case "cborObject": 196 | cborObject = CBOR.decode(CBOR.fromHex(argument)); 197 | break; 198 | 199 | case "diag": 200 | cborObject = CBOR.diagDecode(argument); 201 | break; 202 | 203 | case "data": 204 | cborObject = CBOR.Bytes(CBOR.fromHex(argument)); 205 | break; 206 | 207 | case "date": 208 | cborObject = CBOR.Tag(DATE_TAG, CBOR.String(argument)); 209 | break; 210 | 211 | case "uri": 212 | cborObject = CBOR.Tag(URI_TAG, CBOR.String(argument)); 213 | break; 214 | 215 | case "string": 216 | cborObject = CBOR.String(argument); 217 | break; 218 | 219 | case "number": 220 | if (argument.match(/^[\-\+]?\d+$/)) { 221 | let bigInt = BigInt(argument); 222 | // dCBOR limit checking 223 | if (bigInt > 0xffffffffffffffffn || bigInt < -0x8000000000000000n) { 224 | fatal("integer out of range: " + argument); 225 | } 226 | cborObject = CBOR.BigInt(bigInt); 227 | } else { 228 | cborObject = CBOR.Float(Number(argument)); 229 | } 230 | break; 231 | 232 | default: 233 | fatal("unknown type: " + type); 234 | } 235 | let envelope = CBOR.Tag(SUBJECT_TAG, cborObject).encode(); 236 | process.stdout.write(ENVELOPE_UR + byteWordsEncode(envelope)); 237 | } 238 | 239 | function formatCommand() { 240 | let type; 241 | let cborObject; 242 | if (args.length <= 2) { 243 | type = "envelope"; 244 | cborObject = getEnvelope(1); 245 | } else { 246 | if (getArgument(1) != "--type") fatal("\"--type\" missing"); 247 | type = getArgument(2); 248 | cborObject = getEnvelope(3); 249 | } 250 | switch (type) { 251 | case "cbor": 252 | console.log(CBOR.toHex(cborObject.encode())); 253 | break; 254 | 255 | case "diag": 256 | console.log(cborObject.toString()); 257 | break; 258 | 259 | case "envelope": 260 | fatal("not implemented"); 261 | break; 262 | 263 | default: 264 | fatal("unknown type: " + type); 265 | } 266 | } 267 | 268 | function digestCommand() { 269 | const hash = Crypto.createHash('sha256'); 270 | hash.update(getEnvelope(1).getTaggedObject().encode()); 271 | console.log(byteWordsEncode(new Uint8Array(hash.digest()))); 272 | } 273 | 274 | function bw2hexCommand() { 275 | let argument = getLastArgument(1); 276 | let index = argument.indexOf("/"); 277 | console.log(CBOR.toHex(byteWordsDecode(index >= 0 ? argument.substring(index + 1) : argument))); 278 | } 279 | 280 | function hex2bwCommand() { 281 | console.log(byteWordsEncode(CBOR.fromHex(getLastArgument(1)))); 282 | } 283 | 284 | // Here it all begins... 285 | if (args.length == 0) { 286 | console.log("\n\ 287 | envelope subject type {cbor|diag|data|date|uri|number} argument\n\ 288 | format [--type {cbor|diag}] ur:envelope/ccccc\n\ 289 | digest ur:envelope/ccccc\n\ 290 | bw2hex [ur:xxxxx/]ccccc\n\ 291 | hex2bw hhhhhh"); 292 | process.exit(3); 293 | } 294 | let command = args[0]; 295 | switch (command) { 296 | case "subject": 297 | subjectCommand(); 298 | break; 299 | 300 | case "format": 301 | formatCommand(); 302 | break; 303 | 304 | case "digest": 305 | digestCommand(); 306 | break; 307 | 308 | case "bw2hex": 309 | bw2hexCommand(); 310 | break; 311 | 312 | case "hex2bw": 313 | hex2bwCommand(); 314 | break; 315 | 316 | default: 317 | fatal("unknown command: " + command); 318 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | --------------------------------------------------------------------------------