node-forge 0.6.47 → 0.7.1

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.
Files changed (67) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/LICENSE +3 -3
  3. package/README.md +254 -175
  4. package/dist/forge.all.min.js +11 -0
  5. package/dist/forge.all.min.js.map +1 -0
  6. package/dist/forge.min.js +10 -0
  7. package/dist/forge.min.js.map +1 -0
  8. package/dist/prime.worker.min.js +2 -0
  9. package/dist/prime.worker.min.js.map +1 -0
  10. package/flash/README.md +48 -0
  11. package/flash/package.json +28 -0
  12. package/flash/swf/SocketPool.swf +0 -0
  13. package/{js → lib}/aes.js +5 -61
  14. package/{js → lib}/aesCipherSuites.js +4 -58
  15. package/{js → lib}/asn1.js +371 -132
  16. package/{js → lib}/cipher.js +3 -59
  17. package/{js → lib}/cipherModes.js +3 -65
  18. package/{js → lib}/debug.js +2 -58
  19. package/{js → lib}/des.js +6 -63
  20. package/lib/forge.js +13 -0
  21. package/{js → lib}/form.js +5 -13
  22. package/{js → lib}/hmac.js +4 -58
  23. package/{js → lib}/http.js +15 -20
  24. package/lib/index.all.js +16 -0
  25. package/lib/index.js +34 -0
  26. package/{js → lib}/jsbn.js +3 -60
  27. package/{js → lib}/kem.js +5 -58
  28. package/{js → lib}/log.js +3 -58
  29. package/lib/md.all.js +13 -0
  30. package/lib/md.js +11 -0
  31. package/{js → lib}/md5.js +4 -60
  32. package/lib/mgf.js +12 -0
  33. package/lib/mgf1.js +57 -0
  34. package/lib/oids.js +159 -0
  35. package/{js → lib}/pbe.js +29 -79
  36. package/{js → lib}/pbkdf2.js +10 -64
  37. package/{js → lib}/pem.js +3 -58
  38. package/{js → lib}/pkcs1.js +6 -59
  39. package/{js → lib}/pkcs12.js +15 -74
  40. package/{js → lib}/pkcs7.js +12 -72
  41. package/{js → lib}/pkcs7asn1.js +4 -58
  42. package/{js → lib}/pki.js +12 -71
  43. package/{js → lib}/prime.js +18 -58
  44. package/{js → lib}/prime.worker.js +4 -1
  45. package/{js → lib}/prng.js +5 -62
  46. package/{js → lib}/pss.js +7 -61
  47. package/{js → lib}/random.js +11 -57
  48. package/{js → lib}/rc2.js +13 -73
  49. package/{js → lib}/rsa.js +13 -71
  50. package/{js → lib}/sha1.js +4 -60
  51. package/{js → lib}/sha256.js +4 -60
  52. package/{js → lib}/sha512.js +19 -61
  53. package/{js → lib}/socket.js +8 -63
  54. package/{js → lib}/ssh.js +7 -66
  55. package/{js → lib}/task.js +5 -58
  56. package/{js → lib}/tls.js +10 -67
  57. package/{js → lib}/tlssocket.js +6 -61
  58. package/{js → lib}/util.js +39 -68
  59. package/{js → lib}/x509.js +25 -102
  60. package/{js → lib}/xhr.js +12 -15
  61. package/package.json +58 -21
  62. package/js/forge.js +0 -94
  63. package/js/md.js +0 -75
  64. package/js/mgf.js +0 -67
  65. package/js/mgf1.js +0 -112
  66. package/js/oids.js +0 -288
  67. package/swf/SocketPool.swf +0 -0
@@ -61,9 +61,14 @@
61
61
  *
62
62
  * The OID for the RSA key algorithm is: 1.2.840.113549.1.1.1
63
63
  */
64
- (function() {
65
- function initModule(forge) {
66
- /* ########## Begin module implementation ########## */
64
+ var forge = require('./forge');
65
+ require('./asn1');
66
+ require('./jsbn');
67
+ require('./oids');
68
+ require('./pkcs1');
69
+ require('./prime');
70
+ require('./random');
71
+ require('./util');
67
72
 
68
73
  if(typeof BigInteger === 'undefined') {
69
74
  var BigInteger = forge.jsbn.BigInteger;
@@ -76,7 +81,7 @@ var asn1 = forge.asn1;
76
81
  * RSA encryption and decryption, see RFC 2313.
77
82
  */
78
83
  forge.pki = forge.pki || {};
79
- forge.pki.rsa = forge.rsa = forge.rsa || {};
84
+ module.exports = forge.pki.rsa = forge.rsa = forge.rsa || {};
80
85
  var pki = forge.pki;
81
86
 
82
87
  // for finding primes, which are 30k+i for i = 1, 7, 11, 13, 17, 19, 23, 29
@@ -677,7 +682,7 @@ pki.rsa.stepKeyPairGenerationState = function(state, n) {
677
682
  var THIRTY = new BigInteger(null);
678
683
  THIRTY.fromInt(30);
679
684
  var deltaIdx = 0;
680
- var op_or = function(x,y) { return x|y; };
685
+ var op_or = function(x, y) { return x|y; };
681
686
 
682
687
  // keep stepping until time limit is reached or done
683
688
  var t1 = +new Date();
@@ -880,7 +885,7 @@ pki.rsa.generateKeyPair = function(bits, e, options, callback) {
880
885
 
881
886
  // if native code is permitted and a callback is given, use native
882
887
  // key generation code if available and if parameters are acceptable
883
- if(!forge.disableNativeCode && callback &&
888
+ if(!forge.options.usePureJavaScript && callback &&
884
889
  bits >= 256 && bits <= 16384 && (e === 0x10001 || e === 3)) {
885
890
  if(_detectSubtleCrypto('generateKey') && _detectSubtleCrypto('exportKey')) {
886
891
  // use standard native generateKey
@@ -892,7 +897,8 @@ pki.rsa.generateKeyPair = function(bits, e, options, callback) {
892
897
  }, true /* key can be exported*/, ['sign', 'verify'])
893
898
  .then(function(pair) {
894
899
  return window.crypto.subtle.exportKey('pkcs8', pair.privateKey);
895
- }).catch(function(err) {
900
+ // avoiding catch(function(err) {...}) to support IE <= 8
901
+ }).then(undefined, function(err) {
896
902
  callback(err);
897
903
  }).then(function(pkcs8) {
898
904
  if(pkcs8) {
@@ -1788,67 +1794,3 @@ function _publicKeyFromJwk(jwk) {
1788
1794
  function _base64ToBigInt(b64) {
1789
1795
  return new BigInteger(forge.util.bytesToHex(forge.util.decode64(b64)), 16);
1790
1796
  }
1791
-
1792
- } // end module implementation
1793
-
1794
- /* ########## Begin module wrapper ########## */
1795
- var name = 'rsa';
1796
- if(typeof define !== 'function') {
1797
- // NodeJS -> AMD
1798
- if(typeof module === 'object' && module.exports) {
1799
- var nodeJS = true;
1800
- define = function(ids, factory) {
1801
- factory(require, module);
1802
- };
1803
- } else {
1804
- // <script>
1805
- if(typeof forge === 'undefined') {
1806
- forge = {};
1807
- }
1808
- return initModule(forge);
1809
- }
1810
- }
1811
- // AMD
1812
- var deps;
1813
- var defineFunc = function(require, module) {
1814
- module.exports = function(forge) {
1815
- var mods = deps.map(function(dep) {
1816
- return require(dep);
1817
- }).concat(initModule);
1818
- // handle circular dependencies
1819
- forge = forge || {};
1820
- forge.defined = forge.defined || {};
1821
- if(forge.defined[name]) {
1822
- return forge[name];
1823
- }
1824
- forge.defined[name] = true;
1825
- for(var i = 0; i < mods.length; ++i) {
1826
- mods[i](forge);
1827
- }
1828
- return forge[name];
1829
- };
1830
- };
1831
- var tmpDefine = define;
1832
- define = function(ids, factory) {
1833
- deps = (typeof ids === 'string') ? factory.slice(2) : ids.slice(2);
1834
- if(nodeJS) {
1835
- delete define;
1836
- return tmpDefine.apply(null, Array.prototype.slice.call(arguments, 0));
1837
- }
1838
- define = tmpDefine;
1839
- return define.apply(null, Array.prototype.slice.call(arguments, 0));
1840
- };
1841
- define([
1842
- 'require',
1843
- 'module',
1844
- './asn1',
1845
- './jsbn',
1846
- './oids',
1847
- './pkcs1',
1848
- './prime',
1849
- './random',
1850
- './util'
1851
- ], function() {
1852
- defineFunc.apply(null, Array.prototype.slice.call(arguments, 0));
1853
- });
1854
- })();
@@ -5,13 +5,11 @@
5
5
  *
6
6
  * Copyright (c) 2010-2015 Digital Bazaar, Inc.
7
7
  */
8
- (function() {
9
- /* ########## Begin module implementation ########## */
10
- function initModule(forge) {
8
+ var forge = require('./forge');
9
+ require('./md');
10
+ require('./util');
11
11
 
12
- var sha1 = forge.sha1 = forge.sha1 || {};
13
- forge.md = forge.md || {};
14
- forge.md.algorithms = forge.md.algorithms || {};
12
+ var sha1 = module.exports = forge.sha1 = forge.sha1 || {};
15
13
  forge.md.sha1 = forge.md.algorithms.sha1 = sha1;
16
14
 
17
15
  /**
@@ -319,57 +317,3 @@ function _update(s, w, bytes) {
319
317
  len -= 64;
320
318
  }
321
319
  }
322
-
323
- } // end module implementation
324
-
325
- /* ########## Begin module wrapper ########## */
326
- var name = 'sha1';
327
- if(typeof define !== 'function') {
328
- // NodeJS -> AMD
329
- if(typeof module === 'object' && module.exports) {
330
- var nodeJS = true;
331
- define = function(ids, factory) {
332
- factory(require, module);
333
- };
334
- } else {
335
- // <script>
336
- if(typeof forge === 'undefined') {
337
- forge = {};
338
- }
339
- return initModule(forge);
340
- }
341
- }
342
- // AMD
343
- var deps;
344
- var defineFunc = function(require, module) {
345
- module.exports = function(forge) {
346
- var mods = deps.map(function(dep) {
347
- return require(dep);
348
- }).concat(initModule);
349
- // handle circular dependencies
350
- forge = forge || {};
351
- forge.defined = forge.defined || {};
352
- if(forge.defined[name]) {
353
- return forge[name];
354
- }
355
- forge.defined[name] = true;
356
- for(var i = 0; i < mods.length; ++i) {
357
- mods[i](forge);
358
- }
359
- return forge[name];
360
- };
361
- };
362
- var tmpDefine = define;
363
- define = function(ids, factory) {
364
- deps = (typeof ids === 'string') ? factory.slice(2) : ids.slice(2);
365
- if(nodeJS) {
366
- delete define;
367
- return tmpDefine.apply(null, Array.prototype.slice.call(arguments, 0));
368
- }
369
- define = tmpDefine;
370
- return define.apply(null, Array.prototype.slice.call(arguments, 0));
371
- };
372
- define(['require', 'module', './util'], function() {
373
- defineFunc.apply(null, Array.prototype.slice.call(arguments, 0));
374
- });
375
- })();
@@ -7,13 +7,11 @@
7
7
  *
8
8
  * Copyright (c) 2010-2015 Digital Bazaar, Inc.
9
9
  */
10
- (function() {
11
- /* ########## Begin module implementation ########## */
12
- function initModule(forge) {
10
+ var forge = require('./forge');
11
+ require('./md');
12
+ require('./util');
13
13
 
14
- var sha256 = forge.sha256 = forge.sha256 || {};
15
- forge.md = forge.md || {};
16
- forge.md.algorithms = forge.md.algorithms || {};
14
+ var sha256 = module.exports = forge.sha256 = forge.sha256 || {};
17
15
  forge.md.sha256 = forge.md.algorithms.sha256 = sha256;
18
16
 
19
17
  /**
@@ -327,57 +325,3 @@ function _update(s, w, bytes) {
327
325
  len -= 64;
328
326
  }
329
327
  }
330
-
331
- } // end module implementation
332
-
333
- /* ########## Begin module wrapper ########## */
334
- var name = 'sha256';
335
- if(typeof define !== 'function') {
336
- // NodeJS -> AMD
337
- if(typeof module === 'object' && module.exports) {
338
- var nodeJS = true;
339
- define = function(ids, factory) {
340
- factory(require, module);
341
- };
342
- } else {
343
- // <script>
344
- if(typeof forge === 'undefined') {
345
- forge = {};
346
- }
347
- return initModule(forge);
348
- }
349
- }
350
- // AMD
351
- var deps;
352
- var defineFunc = function(require, module) {
353
- module.exports = function(forge) {
354
- var mods = deps.map(function(dep) {
355
- return require(dep);
356
- }).concat(initModule);
357
- // handle circular dependencies
358
- forge = forge || {};
359
- forge.defined = forge.defined || {};
360
- if(forge.defined[name]) {
361
- return forge[name];
362
- }
363
- forge.defined[name] = true;
364
- for(var i = 0; i < mods.length; ++i) {
365
- mods[i](forge);
366
- }
367
- return forge[name];
368
- };
369
- };
370
- var tmpDefine = define;
371
- define = function(ids, factory) {
372
- deps = (typeof ids === 'string') ? factory.slice(2) : ids.slice(2);
373
- if(nodeJS) {
374
- delete define;
375
- return tmpDefine.apply(null, Array.prototype.slice.call(arguments, 0));
376
- }
377
- define = tmpDefine;
378
- return define.apply(null, Array.prototype.slice.call(arguments, 0));
379
- };
380
- define(['require', 'module', './util'], function() {
381
- defineFunc.apply(null, Array.prototype.slice.call(arguments, 0));
382
- });
383
- })();
@@ -10,13 +10,11 @@
10
10
  *
11
11
  * Copyright (c) 2014-2015 Digital Bazaar, Inc.
12
12
  */
13
- (function() {
14
- /* ########## Begin module implementation ########## */
15
- function initModule(forge) {
13
+ var forge = require('./forge');
14
+ require('./md');
15
+ require('./util');
16
16
 
17
- var sha512 = forge.sha512 = forge.sha512 || {};
18
- forge.md = forge.md || {};
19
- forge.md.algorithms = forge.md.algorithms || {};
17
+ var sha512 = module.exports = forge.sha512 = forge.sha512 || {};
20
18
 
21
19
  // SHA-512
22
20
  forge.md.sha512 = forge.md.algorithms.sha512 = sha512;
@@ -81,12 +79,26 @@ sha512.create = function(algorithm) {
81
79
  _w[wi] = new Array(2);
82
80
  }
83
81
 
82
+ // determine digest length by algorithm name (default)
83
+ var digestLength = 64;
84
+ switch (algorithm) {
85
+ case 'SHA-384':
86
+ digestLength = 48;
87
+ break;
88
+ case 'SHA-512/256':
89
+ digestLength = 32;
90
+ break;
91
+ case 'SHA-512/224':
92
+ digestLength = 28;
93
+ break;
94
+ }
95
+
84
96
  // message digest object
85
97
  var md = {
86
98
  // SHA-512 => sha512
87
99
  algorithm: algorithm.replace('-', '').toLowerCase(),
88
100
  blockLength: 128,
89
- digestLength: 64,
101
+ digestLength: digestLength,
90
102
  // 56-bit length of message so far (does not including padding)
91
103
  messageLength: 0,
92
104
  // true message length
@@ -547,57 +559,3 @@ function _update(s, w, bytes) {
547
559
  len -= 128;
548
560
  }
549
561
  }
550
-
551
- } // end module implementation
552
-
553
- /* ########## Begin module wrapper ########## */
554
- var name = 'sha512';
555
- if(typeof define !== 'function') {
556
- // NodeJS -> AMD
557
- if(typeof module === 'object' && module.exports) {
558
- var nodeJS = true;
559
- define = function(ids, factory) {
560
- factory(require, module);
561
- };
562
- } else {
563
- // <script>
564
- if(typeof forge === 'undefined') {
565
- forge = {};
566
- }
567
- return initModule(forge);
568
- }
569
- }
570
- // AMD
571
- var deps;
572
- var defineFunc = function(require, module) {
573
- module.exports = function(forge) {
574
- var mods = deps.map(function(dep) {
575
- return require(dep);
576
- }).concat(initModule);
577
- // handle circular dependencies
578
- forge = forge || {};
579
- forge.defined = forge.defined || {};
580
- if(forge.defined[name]) {
581
- return forge[name];
582
- }
583
- forge.defined[name] = true;
584
- for(var i = 0; i < mods.length; ++i) {
585
- mods[i](forge);
586
- }
587
- return forge[name];
588
- };
589
- };
590
- var tmpDefine = define;
591
- define = function(ids, factory) {
592
- deps = (typeof ids === 'string') ? factory.slice(2) : ids.slice(2);
593
- if(nodeJS) {
594
- delete define;
595
- return tmpDefine.apply(null, Array.prototype.slice.call(arguments, 0));
596
- }
597
- define = tmpDefine;
598
- return define.apply(null, Array.prototype.slice.call(arguments, 0));
599
- };
600
- define(['require', 'module', './util'], function() {
601
- defineFunc.apply(null, Array.prototype.slice.call(arguments, 0));
602
- });
603
- })();
@@ -5,12 +5,11 @@
5
5
  *
6
6
  * Copyright (c) 2010-2013 Digital Bazaar, Inc.
7
7
  */
8
- (function() {
9
- /* ########## Begin module implementation ########## */
10
- function initModule(forge) {
8
+ var forge = require('./forge');
9
+ require('./util');
11
10
 
12
11
  // define net namespace
13
- var net = forge.net = forge.net || {};
12
+ var net = module.exports = forge.net = forge.net || {};
14
13
 
15
14
  // map of flash ID to socket pool
16
15
  net.socketPools = {};
@@ -78,7 +77,7 @@ net.createSocketPool = function(options) {
78
77
  running javascript in the middle of its execution (BAD!) ...
79
78
  calling setTimeout() will schedule the javascript to run on
80
79
  the javascript thread and solve this EVIL problem. */
81
- setTimeout(function(){sp.sockets[e.id][f](e);}, 0);
80
+ setTimeout(function() {sp.sockets[e.id][f](e);}, 0);
82
81
  }
83
82
  };
84
83
  } else {
@@ -145,10 +144,10 @@ net.createSocketPool = function(options) {
145
144
  var socket = {
146
145
  id: id,
147
146
  // set handlers
148
- connected: options.connected || function(e){},
149
- closed: options.closed || function(e){},
150
- data: options.data || function(e){},
151
- error: options.error || function(e){}
147
+ connected: options.connected || function(e) {},
148
+ closed: options.closed || function(e) {},
149
+ data: options.data || function(e) {},
150
+ error: options.error || function(e) {}
152
151
  };
153
152
 
154
153
  /**
@@ -286,57 +285,3 @@ net.createSocket = function(options) {
286
285
  }
287
286
  return socket;
288
287
  };
289
-
290
- } // end module implementation
291
-
292
- /* ########## Begin module wrapper ########## */
293
- var name = 'net';
294
- if(typeof define !== 'function') {
295
- // NodeJS -> AMD
296
- if(typeof module === 'object' && module.exports) {
297
- var nodeJS = true;
298
- define = function(ids, factory) {
299
- factory(require, module);
300
- };
301
- } else {
302
- // <script>
303
- if(typeof forge === 'undefined') {
304
- forge = {};
305
- }
306
- return initModule(forge);
307
- }
308
- }
309
- // AMD
310
- var deps;
311
- var defineFunc = function(require, module) {
312
- module.exports = function(forge) {
313
- var mods = deps.map(function(dep) {
314
- return require(dep);
315
- }).concat(initModule);
316
- // handle circular dependencies
317
- forge = forge || {};
318
- forge.defined = forge.defined || {};
319
- if(forge.defined[name]) {
320
- return forge[name];
321
- }
322
- forge.defined[name] = true;
323
- for(var i = 0; i < mods.length; ++i) {
324
- mods[i](forge);
325
- }
326
- return forge[name];
327
- };
328
- };
329
- var tmpDefine = define;
330
- define = function(ids, factory) {
331
- deps = (typeof ids === 'string') ? factory.slice(2) : ids.slice(2);
332
- if(nodeJS) {
333
- delete define;
334
- return tmpDefine.apply(null, Array.prototype.slice.call(arguments, 0));
335
- }
336
- define = tmpDefine;
337
- return define.apply(null, Array.prototype.slice.call(arguments, 0));
338
- };
339
- define(['require', 'module'], function() {
340
- defineFunc.apply(null, Array.prototype.slice.call(arguments, 0));
341
- });
342
- })();
@@ -8,11 +8,14 @@
8
8
  *
9
9
  * @author https://github.com/shellac
10
10
  */
11
- (function() {
12
- /* ########## Begin module implementation ########## */
13
- function initModule(forge) {
11
+ var forge = require('./forge');
12
+ require('./aes');
13
+ require('./hmac');
14
+ require('./md5');
15
+ require('./sha1');
16
+ require('./util');
14
17
 
15
- var ssh = forge.ssh = forge.ssh || {};
18
+ var ssh = module.exports = forge.ssh = forge.ssh || {};
16
19
 
17
20
  /**
18
21
  * Encodes (and optionally encrypts) a private RSA key as a Putty PPK file.
@@ -231,65 +234,3 @@ function _sha1() {
231
234
  }
232
235
  return sha.digest();
233
236
  }
234
-
235
- } // end module implementation
236
-
237
- /* ########## Begin module wrapper ########## */
238
- var name = 'ssh';
239
- if(typeof define !== 'function') {
240
- // NodeJS -> AMD
241
- if(typeof module === 'object' && module.exports) {
242
- var nodeJS = true;
243
- define = function(ids, factory) {
244
- factory(require, module);
245
- };
246
- } else {
247
- // <script>
248
- if(typeof forge === 'undefined') {
249
- forge = {};
250
- }
251
- return initModule(forge);
252
- }
253
- }
254
- // AMD
255
- var deps;
256
- var defineFunc = function(require, module) {
257
- module.exports = function(forge) {
258
- var mods = deps.map(function(dep) {
259
- return require(dep);
260
- }).concat(initModule);
261
- // handle circular dependencies
262
- forge = forge || {};
263
- forge.defined = forge.defined || {};
264
- if(forge.defined[name]) {
265
- return forge[name];
266
- }
267
- forge.defined[name] = true;
268
- for(var i = 0; i < mods.length; ++i) {
269
- mods[i](forge);
270
- }
271
- return forge[name];
272
- };
273
- };
274
- var tmpDefine = define;
275
- define = function(ids, factory) {
276
- deps = (typeof ids === 'string') ? factory.slice(2) : ids.slice(2);
277
- if(nodeJS) {
278
- delete define;
279
- return tmpDefine.apply(null, Array.prototype.slice.call(arguments, 0));
280
- }
281
- define = tmpDefine;
282
- return define.apply(null, Array.prototype.slice.call(arguments, 0));
283
- };
284
- define([
285
- 'require',
286
- 'module',
287
- './aes',
288
- './hmac',
289
- './md5',
290
- './sha1',
291
- './util'
292
- ], function() {
293
- defineFunc.apply(null, Array.prototype.slice.call(arguments, 0));
294
- });
295
- })();
@@ -7,9 +7,10 @@
7
7
  *
8
8
  * Copyright (c) 2009-2013 Digital Bazaar, Inc.
9
9
  */
10
- (function() {
11
- /* ########## Begin module implementation ########## */
12
- function initModule(forge) {
10
+ var forge = require('./forge');
11
+ require('./debug');
12
+ require('./log');
13
+ require('./util');
13
14
 
14
15
  // logging category
15
16
  var cat = 'forge.task';
@@ -617,7 +618,7 @@ var finish = function(task, suppressCallbacks) {
617
618
  };
618
619
 
619
620
  /* Tasks API */
620
- forge.task = forge.task || {};
621
+ module.exports = forge.task = forge.task || {};
621
622
 
622
623
  /**
623
624
  * Starts a new task that will run the passed function asynchronously.
@@ -722,57 +723,3 @@ forge.task.createCondition = function() {
722
723
 
723
724
  return cond;
724
725
  };
725
-
726
- } // end module implementation
727
-
728
- /* ########## Begin module wrapper ########## */
729
- var name = 'task';
730
- if(typeof define !== 'function') {
731
- // NodeJS -> AMD
732
- if(typeof module === 'object' && module.exports) {
733
- var nodeJS = true;
734
- define = function(ids, factory) {
735
- factory(require, module);
736
- };
737
- } else {
738
- // <script>
739
- if(typeof forge === 'undefined') {
740
- forge = {};
741
- }
742
- return initModule(forge);
743
- }
744
- }
745
- // AMD
746
- var deps;
747
- var defineFunc = function(require, module) {
748
- module.exports = function(forge) {
749
- var mods = deps.map(function(dep) {
750
- return require(dep);
751
- }).concat(initModule);
752
- // handle circular dependencies
753
- forge = forge || {};
754
- forge.defined = forge.defined || {};
755
- if(forge.defined[name]) {
756
- return forge[name];
757
- }
758
- forge.defined[name] = true;
759
- for(var i = 0; i < mods.length; ++i) {
760
- mods[i](forge);
761
- }
762
- return forge[name];
763
- };
764
- };
765
- var tmpDefine = define;
766
- define = function(ids, factory) {
767
- deps = (typeof ids === 'string') ? factory.slice(2) : ids.slice(2);
768
- if(nodeJS) {
769
- delete define;
770
- return tmpDefine.apply(null, Array.prototype.slice.call(arguments, 0));
771
- }
772
- define = tmpDefine;
773
- return define.apply(null, Array.prototype.slice.call(arguments, 0));
774
- };
775
- define(['require', 'module', './debug', './log', './util'], function() {
776
- defineFunc.apply(null, Array.prototype.slice.call(arguments, 0));
777
- });
778
- })();